Converting video from 1080p to 720p with smallest quality loss using ffmpeg

Here is an example which should give you the highest quality video (I'm not speaking about the resulting file size). Note that this video might not be playable on all devices or players:

ffmpeg -i MyMovie.mkv -vf scale=-1:720 -c:v libx264 -crf 0 -preset veryslow -c:a copy MyMovie_720p.mkv

To get a "visually lossless" quality, you can use:

ffmpeg -i MyMovie.mkv -vf scale=-1:720 -c:v libx264 -crf 18 -preset veryslow -c:a copy MyMovie_720p.mkv

Now let's see what we have here:

The scale video filter is for resizing the video. You just set one size – which is the height in this example – and use -1 for the other dimension. ffmpeg will recalculate the correct value automatically while preserving the aspect ratio.

Quality controlled with the -crf option:

The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 18 to be visually lossless or nearly so: it should look the same or nearly the same as the input but it isn't technically lossless.

The range is exponential, so increasing the CRF value +6 is roughly half the bitrate while -6 is roughly twice the bitrate. General usage is to choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value and if it looks bad then choose a lower value.

You can find more info in the x264 encoding guide.

You control the tradeoff between video encoding speed and compression efficiency with the -preset options. Those are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow. Default is medium. The veryslow option offers the best compression efficiency (resulting in a smaller file size for the same quality) but it is very slow – as the name says.

The audio will be stream copied directly from the input file to the output file without any changes.

In case you like to scale in a different size, there are some limitations on the FFMPEG scaling dimensions. It does not accept each height, here is a small list of the best recommendations for dimensions.

Video codecs perform better when the width and height in pixels are multiples of 16. While you can use any width and height in your encoding settings, non-optimal dimensions can result in poor image quality and reduced frame rate. For the best image quality and playback, you should use width and height dimensions for your video that are multiples of 16; your next best choice is multiples of 8, and after that, multiples of 4.

Recommended width and height for videos with 16:9 aspect ratios:

Best Choice:     2nd Best:        3rd Best:
Multiples of 16  Multiples of 8   Multiples of 4
1920 x 1080      1792 x 1008      1856 x 1044
1280 x 720       1152 x 648       1216 x 684
1024 x 576        896 x 504       1088 x 612
 768 x 432        640 x 360        960 x 540
 512 x 288        384 x 216        832 x 468
 256 x 144        128 x 72         704 x 396
                                   576 x 324
                                   448 x 252
                                   320 x 180
                                   192 x 108