Creating a video from a lot of images

On my daughters second birthday, I placed the gopro in a corner of the living room and had it shoot a photo every minute. Since it cost me quite some time to get those pictures into a video, I figured I’d share how it worked for me.

Before you begin, there are some tools you need to install in order for the script to work:

  • imagemagick
  • jhead
  • libav-tools

The first step is to convert the images to a lower resolution (a video with more than 1920×1080 pixels rarely makes any sense). Then, in order for avconv to be able to read multiple images, you have to rename the pictures so the filenames contain sequential numbers. Sounds weird? Well, here’s a quote from the avconv manpage:


If the pattern contains “%d”

all the following numbers must sequential. This limitation may be hopefully fixed.

The third step, at least for me, was to insert a timestamp into the video, so one could see in the video how the day evolved. I read that timestamp from the image file’s exif information and then place it into the lower left corner of the image.

Last step is to actually create the video. I played with the avconv settings a bit and found that using 5 pictures per second (-r 5) does not make the video take too long and you still get an idea of the day. If you want to tune the timelapse, try changing the -r 5 to something different.

Here it goes:

mkdir caption
i=1
for f in *JPG *jpg; do
  text=$(jhead $f | grep ^Date | cut -b 27-31);
  echo "Converting $f and inserting \"$text\""
  convert -geometry 1920 -font Courier-bold -pointsize 80 \ 
  -fill purple -draw "text 0,1420\"$text\"" $f caption/video-$i.JPG;
  i=$((i+1));
done
cd caption
# create video
avconv -r 5 -f image2 -i video-%d.JPG -r 25 -b 65536k video.avi

The video should now be available in the newly created “caption” folder.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s