ffmpeg fix watermark size or percentage

2019-01-29 11:54发布

问题:

i have some videos and i want to add watermark to them but problem is coz in every video "watermark size" is different (in some videos watermark is smaller and in some is bigger - i think because of video input size coz its different)

here is my ffmpeg command (just link is different)

ffmpeg -i "http://VIDEO-LINK" -i "/var/www/logo/logo.png" -filter_complex 'overlay=17:17' -vcodec h264 -crf 25 -preset veryfast -maxrate 600k -bufsize 600k -aspect '640:360' -s '640:360' -acodec libfdk_aac -hls_time 10 -hls_wrap 10 -start_number 1 -y "1.m3u8"

is there a way to make any percentage or fixed watermark based on output which is 640x360

coz if input video is 640x360 it show big watermark with this command if input link is 1280x720 then watermark is so small

回答1:

You can use the scale2ref filter.

-filter_complex "[1][0]scale2ref=iw/8:ih/8[wm][vid];[vid][wm]overlay=17:17[out]"

If the aspect ratio of your watermark is not the same as your video inputs, then the scale2ref will distort your logo. It's best to perform a one-time operation where the logo is padded so that the image has the same aspect ratio as your videos.