How to Create a Time Lapse Video using FFMPEG

Since I just got my TV tuner card less then a week ago, I have been learning a thing or two on some video file manipulation. Creating a time lapse was something I wanted to create from my storm chasing video, and this was how I did it.

The shell script below should be saved as time-lapse.sh if you decide to save it. The script must take three (3) parameters. The first one is the input file. The second one is the output file, and the third is the framerate. The lower the framerate, the faster the time lapse. Line 10 takes every ‘n’ frames per second from the video and saves them in a temporary folder in png format. Then, line 11 takes those png images, and converts it back into a video – without sound, and sped up. Easy, yes?

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash

# Description: make time lapse video
# Usage: time-lapse.sh <source-video> <destination-file> <frames>
# Source Video: the video that you are wanting to speed up
# Destination File: the file where the video will be saved
# Frames: the number of frames to pull per second (1 will speed it up the most, 10 will be slower)

mkdir ffmpeg_temp
ffmpeg -i $1 -r $3 -f image2 ffmpeg_temp/%05d.png
ffmpeg -i ffmpeg_temp/%05d.png -b 512 $2
rm -rf ./ffmpeg_temp

I am working on a Nautilus script, so it can show up in a popup menu, but I don’t have that mastered as of yet, so stay tuned. I will post it later.

This entry was posted on Thursday, July 5th, 2007 at 7:15 am and is filed under Linux. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

16 Responses to “How to Create a Time Lapse Video using FFMPEG”

hackhawk October 18th, 2007 at 1:03 am

Cripes! I can’t believe how difficult it is to do something so trivial as turn a 30 minute video into a 1 minute video.

I should have remembered ffmpeg from my past while backing up security camera footage at my day job. I should have known that a Linux solution would come to save the day.

I paid $100 for a piece of windows software (Roxio Easy Media Creator 10) that I assumed would do such a stupifyingly simple task as time-lapse video, but it did not. After much google/searching, the only capable purchasable product I found was the Mac/Apple products ($500+).

Thank god for ffmpeg, and that pr0gr4mm3r (Andrew Wells) published this simple how-to on the subject.

One note about this script. Do not specify .AVI as the output as ffmpeg chooses a codec that windows media player will not play. Be sure to choose .MPG as the output file when running this script.

Here is the error message received when choosing .AVI as the output.

“Windows Media Player cannot play the file. The Player might not support the file type or a required codec might not be installed on your computer.”

Great work Andrew Wells!
Thank You
Hack Hawk aka Tech Druid aka Richard

Andrew Wells October 23rd, 2007 at 7:03 pm

I was not able to find a solution in Windows myself. Thanks for your tip on converting to .avi. I usually just use mpegs because that’s what my TV tuner uses by default.

Convert Video to Images and Back Using FFMPEG | Pr0gr4mm3r January 5th, 2008 at 10:20 pm

[...] This post was a variation on my tutorial on creating a time lapse video using FFMPEG. [...]

Kelly A July 12th, 2008 at 6:51 pm

Thanks! In addition to the time lapse, I was also able to modify your script to reverse a video, which is another effect I hadn’t found elsewhere.

Andrew Wells July 12th, 2008 at 7:00 pm

Awesome. What did you do to reverse the video?

jonobo November 30th, 2008 at 4:12 pm

Cool Script. Did some good work for me ;)

I am interested in the “reverse”-Script too ;)

Yep. I know. I could do it all on my own – BUT – there is so much interesting to learn in this world that i need 1000Days per Day to do all the things that i want – so sometimes just copying a script i good. Writing it again would be useless ;)

Can i post this script in my just growing and absolutely chaotic Video-on-Linux-Wiki-Project?

Peace,

;j

Andrew Wells November 30th, 2008 at 4:21 pm

Hi, jonobo.  Redistribution is allowed, but please see the license link at the bottom of this page for the legal details.

Vidal April 16th, 2009 at 5:07 pm

Hi.
Just to say that I’ve changed some part of the script to get 720×576 videos at high bps output (=high quality)
Maybe I will automate it so the parameters can be set from command line.
——————-
mkdir ffmpeg_temp
ffmpeg -i $1 -r $3 -f image2 ffmpeg_temp/%05d.png
ffmpeg -i ffmpeg_temp/%05d.png -s 720×576 -b 9000k $2
rm -rf ./ffmpeg_temp

Simple time lapse video in Linux | cenolan.com May 10th, 2009 at 11:24 am

[...] methods and suggestions but not really anything that suited what I wanted. Andrew Wells suggests making a movie and then processing it with ffmpeg to only store 1 in every n frames. That seems a neat solution but I wanted to take a series of [...]

PeEll June 14th, 2009 at 5:52 pm

Very interesting strategy, and the best I have seen so far.  But what about filesize?  I’m time-lapsing a 500MB .ogv file right now, and the intermediate files are going to take up around 4.5GB during the process.  It seems like there should be a way to do this without the massive intermediate storage requirements.

havoc July 29th, 2009 at 7:21 pm

I like mencoder’s output better than ffmpeg (unless it’s something you can use -sameq on), so I modified the script to look like this:

mkdir ffmpeg_temp
ffmpeg -i $1 -r $3 -f image2 ffmpeg_temp/%05d.png
# ffmpeg -i ffmpeg_temp/%05d.png -b 512 $2
cd ffmpeg_temp
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4 -o ../$2 -fps 20 ‘mf://*png’
cd ..
rm -rf ./ffmpeg_temp

Sarah November 9th, 2009 at 9:01 pm

Just wanted to say, that I was looking online at how to speed a movie up in ffmpeg for a presentation and came across your page. I cut and pasted the shell script into my /bin and I was good to go! Thanks for doing the work for me!! Much appreciated.

blog.flo.cx » How to make time-lapse videos on a motorcycle… January 5th, 2010 at 10:24 am

[...] i used ffmpeg to extract images out of the video and to unite them to a timelapse video. using this tutorial and the man pages i was able to come up with this: #!/bin/bash # sample usage: ./timelapsify.sh [...]

Philippe N June 28th, 2010 at 8:52 am

Thank you !
Very simple to understand  & easy to use. Just like Linux !

rosch October 29th, 2011 at 8:27 am

I suggest not removing the images (e.g. no rm line): in case the output video is not written you lose the pictures’ folder and have to start from the beginning. This can be time consuming if your input video is big in size..
cheers.

Leave a Reply