SD into HD

Problem

Upscale and pillar-box a SD video file into a HD video file.

Solution

ffmpeg \
    -i input_file \
    -filter:v \
        "scale=1440:1080:flags=lanczos, \
        pad=1920:1080:240:0" \
    -c:a copy \
    output_file

Command syntax

ffmpeg
starts the command
-i input_file
path, name and extension of the input file
-filter:v "scale=1440:1080:flags=lanczos, pad=1920:1080:240:0"
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

We consider here a SD video file having square pixels. 1440 x 1080 pixel is the maximal size in 4:3 aspect ratio fitting into the 1920 x 1080 pixel of HD.

Note that upscaling – including from SD to HD – 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. Multiple filters are separated by a comma.

Note that the "scale=1440:1080" filter works for both upscaling and downscaling. Therefore this filter applies also for example to transform a 2K scan of a 4:3 film into a HD format for post-production and/or dissemination purposes. We use the Lanczos scaling algorithm (flags=lanczos), which is slower but usually produces a better result than the default bilinear algorithm.

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

If the luma coefficients are modified from SD video (according to Rec. 601) to HD video (according to Rec. 709), then you need to set the colour matrix by adding the filter colormatrix=bt601:bt709. Note that today Rec. 709 is often used also for SD.

The audio codec is specified by -codec:audio, which may is usually as -c:a (-codec:a or -c:audio are also possible). 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.


2021-01-11