HD into SD

Problem

Downscale and letter-box a HD video file into a SD video file.

Solution

ffmpeg \
    -i input_file \
    -filter:v \
        "colormatrix=bt709:bt601, \
        scale=640:360:flags=lanczos, \
        pad=640:480:0:60" \
    -c:a copy \
    output_file

Command syntax

ffmpeg
starts the command
-i input_file
path, name and extension of the input file
-filter:v "colormatrix=bt709:bt601, scale=640:360:flags=lanczos, pad=640:480:0:60"
set colour matrix, video scaling and padding
-c:a copy
re-encodes using the same audio codec
output_file
path, name and extension of the output file

Discussion

HD video has 1920 x 1080 pixels and 640 x 360 pixel is the maximal size in 16:9 aspect ratio fitting into the 640 x 480 pixels of SD1.

Downscaling – including from HD to SD – does never increase the quality of the image. At best it’s the same quality.

The video filter is specified by -filter:v. We advise to avoid the alias -vfilter and its abbreviation -vf as well. The quotation marks are not mandatory for these video filters, yet we advice to put multiple filters into quotation marks. The quotation marks allow to insert a space between the filters for readability.

The luma coefficients are modified from HD video (according to Rec. 709) to SD video (according to Rec. 601) by a colour matrix. Note that today Rec. 709 is often used also for SD and you may cancel this parameter.

Note that the "scale=640:360" filter works for both upscaling and downscaling. We use the Lanczos scaling algorithm (flags=lanczos), which is slower but gives better results than the default bilinear algorithm.

The formula pad=640:480:0:60 gives bit by bit exactly the same result if expressed as pad=iw:iw*3/4:(ow-iw)/2:(oh-ih)/2 by using relative values for input width (iw), input height (ih), output width (ow) and output height (oh).

The audio codec is specified by -codec:audio, which may be abbreviated as -c:a (or -codec:a or -c:audio). We advise to avoid the alias -acodec. For silent videos you can replace -c:a copy by -an; for video with sound you may choose to re-encode with another audio codec which is allowed by the container.


Note

1
SD may also have a resolution of 768 x 576 pixels. In this case the padding formula would be pad=768:432:0:72, or the same pad=iw:iw*3/4:(ow-iw)/2:(oh-ih)/2, when expressed using relative values.

2018–07–21