首页 > 解决方案 > How to add image in a video at particular location of the frame using ffmpeg

问题描述

I need to add a image overlay in a video using ffmpeg. ffmpeg -i test.mp4 -i logo.png -filter_complex "[0:v][1:v] overlay=10:10:enable='between(t,1,10)'" output.mp4 I tried the above code but the overlay image size is very hight and it showing on the top possition of the frame. Image1 The image1 showing the result what i get after running the above code. I need the output like image2.image2

标签: imageffmpegoverlayyolo

解决方案


ffmpeg test.mp4 -i logo.png -filter_complex "\
[1][0]scale2ref=w=oh*mdar:h=ih/10[logo][input0];\
[input0][logo]overlay=x=main_w*0.05:(main_h-overlay_h)-(main_h * 
0.1):enable='between(t,1,10)'" output.mp4

Line Description:

  1. Make Logo-height 10% of video-height
  2. x=main_w*0.05 -> position Logo 5% away from the left edge of the screen; (main_h-overlay_h)-(main_h * 0.1) -> position Logo 10% away from the bottom edge of the screen;

If you prefer a fade-in of the logo rather than a sudden appearance use this:

ffmpeg -i test.mp4 -loop 1 -i logo.png -filter_complex "\
[1][0]scale2ref=w=oh*mdar:h=ih/10[logo][input0];\
[logo]format=rgba,\
fade=in:\
st=1:\
d=0.5:\
alpha=1\
,fade=out:st=6:d=0.5:alpha=1\
[logo2];\
[input0][logo2]overlay=x=main_w*0.05:(main_h-overlay_h)-(main_h * 0.1):" output.mp4

(You can delete Line 8 if you don't want to fade out.)


推荐阅读