SD into HD

Problem

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

Solution

ffmpeg \
    -i input_file \
    -filter:v \
        "colormatrix=bt601:bt709, \
        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 "colormatrix=bt601:bt709, scale=1440:1080:flags=lanczos, pad=1920:1080:240:0"
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

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.

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.

The luma coefficients are modified from SD video (according to Rec. 601) to HD video (according to Rec. 709) 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=1440:1080" filter works for both upscaling and downscaling. Therefore this filter applies also e.g. for transforming 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 gives better results 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).

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.


2018–07–21