Mayank Thapliyal
Mayank Thapliyal

Reputation: 39

Combine images into video (with audio in background) in ffmpeg

I have a folder with 15 images and 1 audio file:

image_1.jpg, image_2.jpg, image_3.jpg ..... and music.webm

(Also resolution of images is 1440x720)

I want to combine these images into a video with audio in background.And framerate I require is 0.2 (5 second for each frame).I gave a search on Stackoverflow and I found the nearest example and tried.But it failed.

ffmpeg -f image2 -i image%03d.jpg -i music.webm output.mp4

(Actually I have very little knowledge of ffmpeg so please excuse my foolishness)

Please help me with my issue.(Also I didn't understood where in the code I have to enter framerate)

Edit:-If needed I can easily tweak with filename of images.Be free to tell me that too

Upvotes: 0

Views: 6446

Answers (2)

Siwei
Siwei

Reputation: 21549

How your command failed? please paste the text.

According to your image file format, the pattern should be: %3d, but not %03d

e.g.

  • image_%d.jpg apply to: image_1.jpg, image_2.jpg, image_3.jpg
  • image_%04d.jpg apply to: image_0001.jpg, image_0002.jpg ... image9999.jpg

and also , when using this "pattern sequence", MAKE SURE:

  1. the sequence should start from xxx001.jpg, otherwise you should specify a parameter -start_index or something.
  2. the sequence must not broken. e.g. image5.jpg, image6.jpg, (missing 7 ) image8.jpg

refer:

https://ffmpeg.org/ffmpeg-formats.html#image2-2

https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence

Upvotes: 1

Felixkruemel
Felixkruemel

Reputation: 514

Try this:

ffmpeg -r 0.2 -i image_%02d.jpg -i music.webm -vcodec libx264 -crf 25 -preset veryslow -acodec copy video.mkv

So -r specifies fps (I actually didn't try using a float value there, but try it)

-vcodec specifies video codec, -crf quality, preset the encoding speed (slower is more efficient), -acodec copy says audio should be copied.

I think that should work, give it a try. You will need to rename the images to image_01.jpg image_02...

Also have a look here: How to create a video from images with FFmpeg?

Upvotes: 0

Related Questions