How to overlay/place an image on a video in ffmpeg

2019-06-08 07:04发布

问题:

This question already has an answer here:

  • How to add transparent watermark in center of a video with ffmpeg? 1 answer

Hey guys I am trying to overlay an image at the cntre of a video in ffmpeg like this:

ffmpeg -i video.mp4 -i image.png -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" -pix_fmt yuv420p -c:a copy output.mp4

But the image get placed on the top-left side of the video. How can I adjust the image to the centre?

回答1:

Use

ffmpeg -i video.mp4 -i image.png -filter_complex "[0:v][1:v] overlay=(W-w)/2:(H-h)/2:enable='between(t,0,20)'" -pix_fmt yuv420p -c:a copy output.mp4

W amd H are the base video's dimensions. And w and h the overlay video's.