2

I want to create a video or slideshow from a batch of 400 images (.jpg) with different time lapse (I have a text file which shows how much time for each image in millisecond)

For example:

image 0001.jpg is 225 msec
image 0002.jpg is 480 msec
image 0003.jpg is 1200 msec

How can I create such a video with minimal effort?

Amr Ali
  • 21

1 Answers1

2

One way is to create a video from each image, and then combine them all. With mencoder you could do the following:

This will create a video with 1 frame per second from image.jpg:

mencoder "mf://image.jpg" -ovc x264 -mf  fps=1  -o output.avi

This will take two videos and merge them into one:

mencoder -ovc copy -oac copy video1.avi video2.avi -o completevideos.avi 

It might look something like this. Each line of durations.txt contains a duration (in milliseconds here), and images are named as in your example. This is meant as an example and may not work as presented:

i = 0
while read line; do
    padded = $(printf "%04d\n" $i)
    fps = $(echo "scale=3; 1/$i/1000" | bc -q 2>/dev/null)
    if [ i -eq 0 ]; then
        mencoder "mf://image$padded.jpg" -ovc x264 -mf  fps=$fps -o previous.avi
    else
        mencoder "mf://image$padded.jpg" -ovc x264 -mf  fps=$fps -o next.avi
        mencoder -ovc copy -oac copy previous.avi next.avi -o building.avi
        rm previous.avi
        mv building.avi previous.avi
    fi
    i = $[i + 1];
done < durations.txt

The ffmpeg tool has similar functions:

ffmpeg -loop 1 -i img.png -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4
ffmpeg -i concat:"intermediate1.mpg|intermediate2.mpg" -c copy intermediate_all.mpg
Nattgew
  • 1,155