Pad 4:3 into 16:9

Problem

Pad a video file with 4:3 aspect ratio into a video file with 16:9 aspect ration by correct pillar-boxing (without scaling).

Solution

ffmpeg \
    -i input_file \
    -filter:v "pad=ih*16/9:ih:(ow-iw)/2:(oh-ih)/2" \
    -c:a copy \
    output_file

Command syntax

ffmpeg
starts the command
-i input_file
path, name and extension of the input file
-filter:v "pad=ih*16/9:ih:(ow-iw)/2:(oh-ih)/2"
video padding
-c:a copy
re-encodes using the same audio codec
output_file
path, name and extension of the output file

Discussion

The video filter is specified by -filter:v. We advise to avoid the alias -vfilter and its abbreviation -vf as well. This resolution independent formula is actually padding any aspect ratio into 16:9 by pillar-boxing, because the video filter uses relative values for input width (iw), input height (ih), output width (ow) and output height (oh). Of course, in this formula the brackets are compulsory. The quotation marks are not mandatory, but we strongly recommend their use. Also remember that without the quotation marks, the parentheses must be escaped:
-filter:v pad=ih*16/9:ih:\(ow-iw\)/2:\(oh-ih\)/2.

For the specific transformation from SD into HD scaling is also needed.

The audio codec is specified by -codec:audio, which is usually abbreviated 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.


2024-02-07