Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify unordered image list?

Tags:

ffmpeg

I'm trying to figure out how to specify a specific list of images to be converted into a video. I do know that we can do something like:

ffmpeg -i image_04%d.png

That would pick all the images from the folder that match the sequence. However in my case the image files are no necessarily in the order as its name implies. The reason is that the order is kept on a database and the file names are essentially the database row id.

How could I specify the correct input sequence? I'm essentially calling ffmpeg from code and not from the command line. So any changes ideas to the code are also welcomed.

Thanks!

like image 852
Jona Avatar asked Apr 28 '12 18:04

Jona


1 Answers

Here is a script along Kevin's idea which works for me. You might want to replace the file name pattern (shot*.png) and the output filename movie.mp4. All frame_ ... files are removed by the script when finished.

# script to create movie from multiple png files
# taken in choronoligcal order

# start at 0
count=0
# take all files named shot - something ordered by date
for f in `ls -rt shot*.png`
do 
  # get the index in 0000 format
  printf -v counts "%04d" $count
    # link file to a frame_0000  named symbolic link
    ln -s $f frame_$counts.png
    # increment counter
  count=`expr $count + 1`
done
# create movie
# slowed down by factor 5
# ffmpeg -f image2 -i frame_%04d.png -vcodec mpeg4 -vf "setpts=5*PTS" movie.mp4
ffmpeg -i frame_%04d.png movie.mp4
# remove the links
rm frame_*.png
like image 169
Wolfgang Fahl Avatar answered Oct 20 '22 03:10

Wolfgang Fahl