How to overlay a transparent PNG over video and scale to video size in FFmpeg

0

Right now I overlay a transparent PNG over a video first converting them both to the same size, but would love to just have it scale within the same command. Here’s the command now:

ffmpeg -y -i video.mp4 -i overlay.png -filter_complex 'overlay[out],amix=inputs=1,pan=stereo:c0=c0:c1=c1' -map '[out]' output.mp4

The best command should also permit a video that does not have an audio track and still overlay the PNG.

Daniel Jacob Archer

Posted 2016-08-03T00:05:49.347

Reputation: 49

Answers

0

Use

ffmpeg -y -i video.mp4 -i overlay.png
 -filter_complex "[1][0]scale2ref[i][m];[m][i]overlay[v]"
 -map "[v]" -map 0:a? -ac 2 output.mp4

The scale2ref scales the first input (to the filter) to the size of the second. The input pad indexes 0, and 1 refer to the first and 2nd input to FFmpeg, as that count begins from zero.

-map 0:a? - the ? tells FFmpeg to map the audio contingently i.e. if present. I have removed the amix since a) filters within a filter complex can't be contingent and b) there's only one input so there's nothing to 'mix'.

Gyan

Posted 2016-08-03T00:05:49.347

Reputation: 21 016

This is great - if I want to scale the second input to the size of the first, would it be [0][1]scale2ref[i][m]? – Daniel Jacob Archer – 2016-08-03T16:22:34.880