ffmpeg scale logo size according to video size

时间:2017-08-05 11:36:02

标签: video ffmpeg watermark

I have a ffmpeg command which is working fine to inject 2 image on the top left and bottom right of the video.

ffmpeg -i ori.mp4 -y -i 1.png -i 2.png -filter_complex \
"[0:v][1:v]overlay=20:20[bkg]; \
[bkg][2:v]overlay=(main_w-overlay_w)-20:(main_h-overlay_h)-20" \
-codec:v libx264 -crf 18 -preset slow -pix_fmt yuv420p \
-c:a aac -strict -2 out1.mp4 

this command working fine with video that has large size like 720x480, however when the input video size is 320x240 size, it will overlay half of the video size.

1.png size is: 160x100

2.png size is: 341x44

any idea how to combine the scale2ref into above command?

been trying solution from this link so far no luck.

update 1: i found this command from here

ffmpeg -i ori.mp4 -y -i 1.png \
-filter_complex "[1:v][0:v]scale2ref=iw*0.25:-1[logo1][base]; \
[base][logo1]overlay=20:20[v]" -map [v] -map 0:a \
-codec:v libx264 -crf 18 -preset slow -pix_fmt yuv420p \
-c:a aac -strict -2 out2.mp4 

that command work fine to get one image to scale.

update 2:

ffmpeg -i ori.mp4 -y -i 1.png -i 2.png \
-filter_complex "[1:v][0:v]scale2ref=iw*0.25:-1[logo1][base];\
[base][logo1]overlay=20:20[v];[2:v][0:v]scale2ref=iw*0.30:-1[logo2][base2];\
[base2][logo2]overlay=(main_w-overlay_w)-20:(main_h-overlay_h)-20[v]" \
-map [v] -map 0:a -codec:v libx264 -crf 18 -preset slow -pix_fmt yuv420p \
-c:a aac -strict -2 out4.mp4 

tried above, nothing work. got error like this

Filter overlay has an unconnected output

any help would be great

1 个答案:

答案 0 :(得分:1)

Use

ffmpeg -i ori.mp4 -y -i 1.png -i 2.png -filter_complex \
"[1:v][0:v]scale2ref=160/100*oh:ih/5[v1][bk1];[bk1][v1]overlay=20:20[bkg]; \
 [2:v][bkg]scale2ref=341/44*oh:ih/11[v2][bk2];[bk2][v2]overlay=W-w-20:H-h-20" \
-c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p \
-c:a aac -strict -2 out1.mp4