HandBrake has a command-line version, and it is less scary than its long help text suggests. The presets from the app are available there too, and one option is enough to start.
HandBrakeCLI -z
HandBrakeCLI -i input.mkv -o output.mp4 -Z "Preset Name"
-z (--preset-list) prints the presets your build knows. -Z (--preset) selects one by name. Replace Preset Name with a name from that list, spelled exactly as printed.
The name is case-sensitive, and names with spaces need quotes. The list can differ per operating system and hardware, so don’t copy a name from a forum post without checking it against your own -z output.
-i is the source and -o the destination file. The container follows the extension you give, so .mp4 and .mkv both work.
A preset is a starting point. Options you add after it override the preset, for example -q 22.0 to set the quality or -e x265 to pick another encoder. The reference also lists --preset-import-file, which loads presets from a JSON file exported from the app, so a preset you tuned in the GUI can be reused in scripts.
Further reading: HandBrake command line reference