Make sure you run the latest version of FFmpeg. For Windows and Linux, static builds are availabe from the homepage. For OS X, you can install FFmpeg through Homebrew.
Then, in the simplest case run:
ffmpeg -i input.mkv -c:v libx264 -c:a libfaac out.mp4
For controlling video quality, set the
crf parameter, which defaults to 23. Lower means better quality, but higher file size. Try values between 19 and 26 to see what fits best. You can also set a certain bit rate, depending on which file size you want. Here, for example, 500 kBit/s:
ffmpeg -i input.mkv -c:v libx264 -crf 23 …
ffmpeg -i input.mkv -c:v libx264 -b:v 500k …
For audio, you can set quality or bit rate too. 100 is the default quality value and higher means better.
ffmpeg -i input.mkv … -c:a libfaac -q:a 100 out.mp4
ffmpeg -i input.mkv … -c:a libfaac -b:a 128k out.mp4
libfaac is not available, I believe you can use
aac instead, with the additional option
Please read our blog post for more info: FFmpeg: The ultimate Video and Audio Manipulation Tool