How to create a video from a series of images with different image lengths?

I want to programmatically create a video file consisting of a series of images. However, I would also like to indicate the duration for each image. I often see ffmpeg examples suggested for similar tasks, but they always take the same duration for each image. Is there an effective way to achieve this? (An ineffective solution can set the frame rate to something high and copy each image repeatedly until it matches the expected duration)

I will dynamically generate each of the images, so if there is a way to encode image data into video clips without writing each image to disk, this is even better. This, however, is not a requirement.

Edit: To be clear, I don't have to use ffmpeg. Other free command line tools are fine, as are video processing libraries. I'm just looking for a good solution.

+4
source share
2 answers

There seems to be no way to have different durations for different images using ffmpeg. I would create separate videos for each of the images and then concatenate them using mencoder as follows:

ffmpeg -f image2 -vframes 30 -i a.jpg -vcodec libx264 -r 1 a.mp4 ffmpeg -f image2 -vframmes 10 -i bjpg -vcodec libx264 -r 1 b.mp4 mencoder -ovc copy -o out.mp4 a.mp4 b.mp4 

The mencoder for the concat operation requires that all output videos have the same resolution, frame rate, and codec.

Here a.mp4 has 30 frames lasting 30 seconds, and b.mp4 has 10 frames in 10 seconds.

+1
source

I managed to solve the same problem with the following commands. vframes is set to the number of seconds * fps In the example, the first video has 100 frames (100 frames / 25 frames per second = 4 seconds), and the second has 200 frames (8 seconds)

 ffmpeg -f image2 -loop 1 -vframes 100 -r 25 -i a.jpg -vcodec mpeg4 a.avi ffmpeg -f image2 -loop 1 -vframes 200 -r 25 -i b.jpg -vcodec mpeg4 b.avi mencoder -ovc copy -o out.mp4 a.mp4 b.mp4 

The mencoder part is similar to the d33pika part

+1
source

All Articles