Free timelapse screencasts in MacOS. Part II: video from snapshots

iMovie is not enough when you want to create a movie from hundreds of snapshots. I’m not able to import them without transitions, so I switched back to what I knew, the Army Knife of video tools: FFMPEG.

Installing it on your Mac is easy with MacPorts, which is similar to apt-get in Ubuntu. Download and install MacPorts first, so you can invoke it from a command line in a  terminal.

Fetching, compiling and installing ffmpeg will probably require more than half an hour, depending on your Internet connection, because it needs a lot of packages that are not installed by default in MacOS. But MacPorts works like a charm:

sudo port install ffmpeg

and wait. Do something interesting meanwhile, like reading a book, having a walk or petting your cat…

Once ffmpeg is in your system, navigate in a terminal to the folder where you stored your screenshots (like those we created with the Python script) and type this:

ffmpeg -r 10 -i img%06d.png -vcodec libx264
  -vpre hq -bf 0 -crf 15 output_video.mp4

That will create an h.264 video using High Quality (-vpre hq, -crf 15)  and a low frame rate (10 fps. Put that BEFORE -i, or it won’t work). B-Frames are removed (-bf 0), otherwise YouTube messes the whole thing. Image file names must be consecutive, just change their name if you used a different one.

And this is the result! Not exactly useful when talking about programming… but it still looks great.

Free timelapse screencasts in MacOS. Part I: snapshots

Medusa is giving a talk entitled ‘Independent Video Game Creation. Exploring the technical and creative process‘ in the incoming Animayo festival. We will build a game from zero to beta in three hours while discussing with the audience what makes a game fun.

We need to prepare some timelapse videos for the artistic part, namely speed paintings of concept art and textures and speed modeling and animation. We may even show some speed programming and speed music composing videos, because these things are pretty attractive once  you create your first one!

While recording the whole screen is quite easy with Quicktime Player X, we needed no more than two frames per second. I finally had to program my own Python script to do that, because everything was either expensive or didn’t meet our needs.

It uses TKinter to ask for the output directory, where it stores two frames each second. Nothing fancy, just simple and practical. Indeed, you have to stop it by pressing CTRL-C if you are using a console, or killing python with CMD-ALT-ESC. But it does its job!

You’ll know it’s working because it uses the ‘screencapture’ command, which makes that cool camera-like click sound when capturing the screen. Twice per second. Yes, I know. Mute your Mac.

import Tkinter, tkFileDialog, tkSimpleDialog
import os
import threading
import time
import sys

def take_snapshot(frame, command):
  frame += 1
  os.system(command  + str(frame).zfill(6)  + ".png")
  threading.Timer(0.5, take_snapshot, 
  [frame, command]).start()

snapshot_id = ""
if (len(sys.argv) == 2):
  snapshot_id = sys.argv[1]
root = Tkinter.Tk()
dirname = tkFileDialog.askdirectory(
  title='Output directory...')
if len(dirname ) > 0:
  print "Storing snapshots in %s" % dirname
  print "Press CTRL-C (probably many times) to stop."
  command = "screencapture " + dirname + "/" + 
take_snapshot(0, command)

Follows up: how to create a video from all these images!