简体   繁体   English

使用 FFMPEG 将带有缩放 + 旋转的图像添加到视频叠加中?

[英]Add image with scale + rotation to video overlay with FFMPEG?

I want to add overlay images to videos with params我想使用参数向视频添加叠加图像

1: w:h --> is width and height of image on the video 1: w:h --> 是视频上图像的宽度和高度

2: r --> Radian is rotation of images 2: r --> 弧度是图像的旋转

3: center (x,y) --> is center point of image in the video 3: center (x,y) --> 是视频中图像的中心点

This is my FFMPEG command :这是我的 FFMPEG 命令:

-i video.mp4 -i image.png filter_complex [1:v]scale=w:h[scale];[scale]rotate=r:ow=iw:oh=ih[rotate];[0:v][rotate]overlay=x-(w/2):y-(h/2)

But the result not correct.但结果不正确。 It's Only work with scale=1 and rotate=0 radian它仅适用于 scale=1 和 rotate=0 弧度

How can i do this ?我怎样才能做到这一点 ?

Use

[1:v]scale=w:h,pad=iw+4:ih+4:black@0[scale];[scale]rotate=r:ow='rotw(r)':oh='roth(r)'[rotate]

A bit of transparent padding is added to the image before rotation.在旋转之前向图像添加一点透明填充。 This is because the rotate filter will fill the gaps in the canvas with the input's border pixel color.这是因为旋转过滤器将使用输入的边框像素颜色填充画布中的间隙。 Also, the output size has to be adjusted to accommodate the whole image after rotation.此外,必须调整输出大小以适应旋转后的整个图像。 See the docs for the rotate filter.请参阅旋转过滤器的文档

用于在视频上旋转、缩放、覆盖和设置图像持续时间的 Ffmpeg 命令

ffmpeg -i input.mp4 -i inputImg.png -filter_complex \"[1:v] rotate=90:c=none:ow=rotw(iw):oh=roth(ih) [rotate];[rotate]scale=100:-1[scale];[0:v][scale] overlay=0:0:enable='between(t,0,2)'[out]\" -map [out] -pix_fmt yuv420p -c:a copy output.mp4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM