[FFmpeg-user] How to scale watermark proportionally to width and height of video frame?

Frank Tetzel s1445051 at mail.zih.tu-dresden.de
Mon Jan 19 17:02:19 CET 2015

> How to scale watermark proportionally video frame size (to width and
> to height of video frame)?
> Now I use the following command:
> ffmpeg -i input.mkv -i logo.png -filter_complex
> "[1:v]scale=w=iw/3:h=ih/3[watermark_scaled];[0:v][watermark_scaled]overlay=x=main_w-overlay_w-main_w/20:y=main_h-overlay_h-main_w/20"
> output.mkv
> I use scale=w=iw/3:h=ih/3, but I can't use "main_w" and "main_h"
> variables in this place. E.g. scale=w=main_w*0.05:main_h*0.05 don't
> work. How to get video frame width and height to use them for scaling
> watermark?


as far as i know, it is not possible. You have to get the video
dimension on an outer layer, like a shell script, and pass it to the
scale filter. All filters only know about their inputs, not about other
filter chains.

Something like:

ffprobe -v quiet -show_streams -select_streams v:0 input.mkv >$streaminfo
width=`grep width $streaminfo | cut -d'=' -f2`
height=`grep height $streaminfo | cut -d'=' -f2`

ffmpeg -i input.mkv -i logo.png -filter_complex

rm $streaminfo


More information about the ffmpeg-user mailing list