Search this site:

2010-05-18

Creating Time Lapse with ffmpeg




Here is how I made this time lapse video from image:

  1. Rename the images in sequence as frameXXX.jpg (where XXX is 000, 001, 002, etc). Many photo viewing software like XnVew (free solution, recommended!) and ACDSee can do this easily
  2. Run the ffmpeg with the following parameter:
    ffmpeg -r 12 -i frame%03d.jpg -sameq -s hd720 -vcodec libx264 -vpre hq -crf 25 OUTPUT.MP4
  3. Done!

You may want to change the -r parameter to your favorite frame rate. If you want 1080p, simply replace the -s hd720 parameter as -s hd1080, or -s 1920x1080 if you want.

One more important point to note is that the order of parameters matters. Any parameters before the -i will become options for input stream. Like if you type something like ffmpeg -r 12 -i blah blah blah, you will make the specified rate meaningless as it will be applied to input stream which are still imagesthis is how the rate parameter should be specified. Make sure that you don't mix them up when you customize the parameter. Another common problem I've seen is the format for -i parameter. It is actually the same as that of the printf() function in C++. For example, frame%03d.jpg will make ffmpeg looks for images with names frame000.jpg, frame001.jpg, frame002.jpg... while frame%05d.jpg means frame00000.jpg, frame00001.jpg, frame00002.jpg...

Yet I think the quality is not very perfect. Maybe need further fine tunning the parameters. Anyone has hints please?

A uncompressed version can be done like this:
  1. Resize your image to your desired output resolution (e.g. 1920x1080, 1280x720, etc)
  2. Rename the images in sequence as frameXXX.jpg (where XXX is 000, 001, 002, etc). Many photo viewing software like XnVew (free solution, recommended!) and ACDSee can do this easily
  3. Run the ffmpeg with the following parameter:
    ffmpeg -r 12 -i frame%03d.jpg -vcodec copy OUTPUT.AVI
  4. Done again!

Enjoy~


9 comments:

  1. Lentamentalisk26 July, 2010 13:08

    Best tutorial I have found on the net yet. Very to the point, and adaptable.
    Here's mine:
    http://www.youtube.com/watch?v=abh3LtAPtTw

    ReplyDelete
  2. wow!!! the clouds in your video are fantastic!!
    i now know that clouds can really be a nice object for time lapse!

    ReplyDelete
  3. Thanks! There are a lot of convoluted posts out there on how to do this - yours was short, sweet, and simple.

    ReplyDelete
  4. How do you run ffmpeg with that parameter? I just can't figure it out.

    ReplyDelete
  5. Hi Circle, do the jpeg files have to be renamed to framexxx?
    I was trying to use the DSC_0001, DSC_0002 etc names that my camera gives but I get this error. Its not easy to rename the files, I dont want to go searching for more software.. thanks

    ReplyDelete
  6. Hi Tommy, I think that replacing frame%03d.jpg with DSC_%05d.jpg will do the trick.

    ReplyDelete
  7. You are probably disappointed with the quality because of the extreme compression in your x264 settings. Try lowering your crf, and using a better encoding preset:

    -vpre slow -crf 15

    or even better:
    -vpre veryslow -crf 15

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Great tutorial.

    To rename a set of images under Linux I made a little bash script.
    With $1 you can supply a path and/or a file prefix.

    #!/bin/bash
    i=0
    ind=0000
    for x in $1*.jpg ; do
      mv "$x" "$1$ind.jpg"
      ((++i))
      ind=$i
      # $ind must have four digits
      for d in 10 100 1000 ; do
        if [ $i -lt $d ]
        then
          ind=0$ind
        fi
      done
    done

    ReplyDelete

HTML Tags allowed (e.g. <b>, <i>, <a>)

Disclaimer

ALL CONTENTS AND INFORMATION IN THIS WEB SITE ARE PROVIDED "AS IT" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE ACCURACY AND AVAILABILITY OF THE CONTENTS, INFORMATION AND THE WEB SITE ITSELF ARE NOT GUARANTEED. THE AUTHOR TAKES NO RESPONSIBILITIES ON ANY COSTS OR DAMAGES (DIRECT OR INDIRECT) ARISING OUT OF OR IN CONNECTION WITH THE ACCESS, USAGE OR INABILITY OF USAGE OF THIS WEB SITE.