Search code examples
ffmpeg

FFmpeg: About filter_complex command


I use this command.

ffmpeg -i Input.mp4 -i logo.png -c:v h264_nvenc -filter_complex "[0:v]scale=-1:720[video];[1:v][video]scale2ref=(iw/ih)*ih/8/sar:ih/8[wm][base];[base][wm]overlay=10:10" output.mp4

But what does this mean?

scale2ref=(iw/ih)*ih/8/sar:ih/8


Solution

  • What scale2ref=(iw/ih)*ih/8/sar:ih/8 does is scale the image height to 1/8th the video's height, and scale the image width to, well, a weird value. If the scale is meant to preserve the image's aspect ratio, use

    scale2ref=oh*mdar:ih/8
    

    (FFmpeg version 4.0 to 7.1)

    Edit: Since FFmpeg 7.1, scale2ref has been merged into existing scale filter with secondary reference input:

    scale=-1:rh/8
    

    Note that this filter outputs single stream of the modified one instead of two video streams.