Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display image for particular time in a video using ffmpeg

Tags:

ffmpeg

I am trying to created a video from the sequence of images. But i have to display each image with different numbers of seconds. How to do this with FFMPEG.

Thanks in advance.

like image 438
Pratik Bhingardeve Avatar asked Jun 18 '13 10:06

Pratik Bhingardeve


2 Answers

There are some hints in the FFmpeg wiki. This one example (second-to-last in the wiki) in particular is likely suitable for your needs:

ffmpeg -loop 1 -f image2 -i img.png -c:v libx264 -t 30 out.mp4

where the number after -t (30 in the example) is the duration of the video in seconds.

Simply execute that command several times like this:

ffmpeg -loop 1 -f image2 -i intro.png -c:v libx264 -t 5 out1.mp4
ffmpeg -loop 1 -f image2 -i someimage.png -c:v libx264 -t 15 out2.mp4
ffmpeg -loop 1 -f image2 -i someotherimage.png -c:v libx264 -t 25 out3.mp4
ffmpeg -loop 1 -f image2 -i outro.png -c:v libx264 -t 10 out4.mp4

And then merge the resulting videos (if you want):

  1. Create a text file (example: videos.txt) where the video filenames are listed.

    file 'out1.mp4'
    file 'out2.mp4'
    file 'out3.mp4'
    file 'out4.mp4'

  2. Run this command (change filenames if needed)

    ffmpeg -f concat -i videos.txt -c copy final_video.mp4

More information about video merging (concatenation) can be found in the wiki.

like image 200
user2448027 Avatar answered Sep 30 '22 20:09

user2448027


The ffmpeg includes a section on exactly this: https://trac.ffmpeg.org/wiki/Slideshow

Here is an example:

Example content of input.txt:

file '/path/to/dog.png'
duration 5
file '/path/to/cat.png'
duration 1
file '/path/to/rat.png'
duration 3
file '/path/to/tapeworm.png'
duration 2
file '/path/to/tapeworm.png'

Then run:

ffmpeg -f concat -i input.txt -vsync vfr -pix_fmt yuv420p -framerate 30 output.mp4

like image 28
Mattwmaster58 Avatar answered Sep 30 '22 20:09

Mattwmaster58