如何使用 ffmpeg 在帧的特定位置的视频中添加图像

How to add image in a video at particular location of the frame using ffmpeg

我需要使用 ffmpeg 在视频中添加图像叠加层。 ffmpeg -i test.mp4 -i logo.png -filter_complex "[0:v][1:v] overlay=10:10:enable='between(t,1,10)'" output.mp4 我尝试了上面的代码,但叠加图像的尺寸非常高,并且显示在框架的顶部位置。 Image1 The image1 showing the result what i get after running the above code. I need the output like image2.image2

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

行说明:

  1. 使徽标高度为视频高度的 10%
  2. x=main_w*0.05 -> 将Logo放置在距屏幕左边缘5%的位置; (main_h-overlay_h)-(main_h * 0.1) -> 将 Logo 放置在距屏幕底部边缘 10% 的位置;

如果您更喜欢徽标的淡入而不是突然出现,请使用此:

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

(不想淡出的可以删除第8行。)

这是因为您的图片尺寸(宽度、高度)很大。 您需要 缩放 image.simple.

ffmpeg -i test.mp4 -i logo.png -filter_complex "[1]scale=300:100;[0:v][1] overlay=10:10:enable='between(t,1,10)'" output.mp4