user1437101
user1437101

Reputation: 107

ffmpeg merge images with first image duration

I'm try to merge some images in a mp4 with ffmpeg. I do it with:

ffmpeg -r 25 -i %06d.jpg -s 480x360 -vcodec libx264 /output.mp4

The first image must have duration of 3 seconds and the others must have framerate of 25.

I know I can do this for set the duration of an image:

-loop 1 -t 3 -i 000000.jpg-s 480x360 -vcodec libx264 output.mp4

But how can I merge the two things?? The first image of 3 seconds and the others image with 25 fps in one mp4 output??

Thank you

Upvotes: 0

Views: 1040

Answers (2)

Chamath
Chamath

Reputation: 2044

I suggest you to create two individual video files separately and join them after. You can try the concat methods available here. Following is a simple concat using filter_complex

ffmpeg -i input_video1 -i input_video2 -filter_complex "
[0:0][0:1][1:0][1:1]concat=n=2:v=1:a=1[outv][outa]" -map [outv] -map [outa] -c:v libx264 output.mp4

If the images are not in the same dimensions you may need to scale them. Two videos may have different sar values and need to adjust them accordingly using setsar. Also feel free to change the video and audio codecs depending on your need of output format as you need to re-encode this.

Hope this helps!

Upvotes: 1

Mark Setchell
Mark Setchell

Reputation: 207405

You can do it with ImageMagick like this, if you have three files called red.png, green.png and blue.png:

convert -delay 300 red.png -delay 40 green.png blue.png anim.mp4

I'll show it as an animated GIF below, by changing the mp4 to gif

enter image description here

The parameter -delay is a setting so it persists until changed, so it aplies to both green.png and blue.png.

You would probably change green.png and blue.png to *.jpg.

ImageMagick is pre-installed on most Linux distros, and available for OSX (ideally via homebrew) and also for Windows.

If you want to use ffmpeg, I think you have a couple of possibilities

a) specify the frame rate as 25 fps but repeat the first frame 75 times like this:

(for i in {1..75}; do printf "file 'red.png'\n"; done; printf "file '%s'\n" *.jpg) > list.txt
ffmpeg -r 25 -f concat -i list.txt -s 480x360 -vcodec libx264  anim.mp4

b) make a 3 second mp4 and another mp4 with 25 fps and concatenate them

Upvotes: 1

Related Questions