I would like to apply a PNG overlay (watermark) to an arbitrary video file using ffmpeg. I would like the video to stay its original size (which I don't know ahead of time), and the PNG to be scaled relative to the video.

For example, the following command places the overlay in the top left:

ffmpeg.exe -i input.mov -i header.png -filter_complex \
    "[0][1] overlay=0:0" output.mkv

And the following command scales the overlay relative to itself (1/5 of the width, height relative):

ffmpeg.exe -i input.mov -i header.png -filter_complex \
    "[1] scale=iw/5:-1 [scaled]; \
    [0][scaled] overlay=0:0" output.mkv

How could I make the overlay 1/5 of the width of input.mov? (For example, is it possible to store and/or query the width of another filter clause?)

The closest question I've come across is Scale watermark overlay by video size with ffmpeg but that answer uses external Linux/Cygwin commands. FFmpeg watermark was also helpful while I was figuring ffmpeg out. However, I'm on Windows and invoking ffmpeg via Python, so I'd like to do it all within the filter_complex clause. If that's not possible, I'd like to know for sure so I can stop trying :)


My approach would be two separate commands, one to calculate the dimensions and another to overlay. You can simply use FFprobe which comes alongside with FFmpeg. To calculate the dimensions you can use the following command.

ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 input_video

This will result like following.



After you can do what ever the math you want and apply this to your overlay command. Also here are some more options for scaling.

Hope this helps!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.