Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't overlay and center a video on top of an image with ffmpeg. The output is 0 seconds long

Tags:

ffmpeg

I have an mp4 that I want to overlay on top of a jpeg. The command I'm using is:

Ffmpeg -y -i background.jpg -i video.mp4 -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy output.mp4

But for some reason, the output is 0 second long but the thumbnail does show the first frame of the video centred on the image properly.

I have tried using -t 4 to set the output's length to 4 seconds but that does not work.

I am doing this on windows.

like image 276
Jose Miralles Avatar asked Oct 27 '25 03:10

Jose Miralles


2 Answers

You need to loop the image. Since it loops indefinitely you then must use the shortest option in overlay so it ends when video.mp4 ends.

ffmpeg -loop 1 -i background.jpg -i video.mp4 -filter_complex \
"overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:shortest=1" \
-codec:a copy -movflags +faststart output.mp4

See overlay documentation for more info.

like image 169
llogan Avatar answered Oct 29 '25 03:10

llogan


Well you should loop the image until the video duration. So to do the you need to add -loop 1 before the input image. Then the image will have a infinite duration. So to control it specify -shortest before the output file which will trim all the streams to the shortest duration among them. Else you can use -t to trim the image duration to the video length. This will do what you want.

Hope this helps!

like image 29
Chamath Avatar answered Oct 29 '25 02:10

Chamath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!