FFMPEG add image at the end of a video
Asked Answered
M

1

7

I need to add an image for one second at the end of a .mp4 video file using FFMPEG. My video size is WxH and my image size is MxM, so video and image sizes are different.

I have tried different options in order to add the image at the end of the video as:

ffmpeg -i "concat: videoIn.mp4|image.jpg" -c copy videoOut.mp4

or

ffmpeg -i videoIn.mp4 -loop 1 -t 1 -i image.jpg -f lavfi -t 2 -i anullsrc -filter_complex "[0:v][0:a][1:v][2:a] concat = n=2:v=1:a=1[v][a] -c:v libx264 -c:a aac -strict -2 -map" [v] "-map" [a]" videoOut.mp4

but none gave me the result I need.

Can someone help me?

Kind regards

Merely answered 26/7, 2018 at 6:14 Comment(0)
V
1

Use

ffmpeg -i videoIn.mp4 -loop 1 -t 1 -i image.jpg -f lavfi -t 1 -i anullsrc -filter_complex "[1:v]scale=WxH:force_original_aspect_ratio=decrease,pad=W:H:'(ow-iw)/2':'(oh-ih)/2'[i];[0:v][0:a][i][2:a] concat=n=2:v=1:a=1[v][a]" -c:v libx264 -c:a aac -map "[v]" -map "[a]" videoOut.mp4

The image is resized to fit within a WxH frame size and then padded to get the video's frame size.

You'll need ffmpeg 3.4.2 or later.

Victoriavictorian answered 26/7, 2018 at 6:48 Comment(7)
But I don't know the video dimensions, and this dimensions can be diferent along the video, due to the user has the cappability to change the video resolution at any time during the video record. And image must be square, due to is a QR CodeMerely
We can work around unknown video dimensions, but dimensions which change during recording is trickier. Are you running this command after the video has been recorded?Victoriavictorian
I believe you're missing a closing quote sirBaalbeer
This answer is terrible. Fails to explain in depth an extremely complex ffmpeg command, which really warrants explanation. I couldn't get it to work. -1Maudemaudie
This is not even close to an "extremely complex ffmpeg command'. And the answer is tailored to the skills of the OP, as demonstrated by the OP in their Q. For an introduction to ffmpeg CLI syntax or filtering, consult the docs. That can't be encapsulated in every answer dealing with some specific ffmpeg task requirement.Victoriavictorian
if you'd like with fade: ffmpeg -i VIDEO.mp4 -loop 1 -framerate 30 -t 5 -i IMAGE.png -f lavfi -t 5 -i anullsrc=r=48000:cl=2 -filter_complex "[0:V]fade=out:1905:1920[vid];[1:V]fade=in:0:15[end];[vid][0:a][end][2]concat=a=1" OUT.mp4 Source: reddit.com/r/ffmpeg/comments/isqx34/…Logician
@Victoriavictorian Maybe not an extremely complex ffmpeg command by ffmpeg standards, but by any other standards it definitely is very complex. I would expect an answer like this to at least explain why each option is required.Isosteric

© 2022 - 2024 — McMap. All rights reserved.