Photobooth Moviemaker

At Rails Girls London Winter 2017, we had a photo booth for the first time. Beside being lots of fun. While flicking though the images I thought they’d look good as a video.

Firing up Processing. I didn’t try to be clever. The program loads all the images into an array and then save the frames as TIFF. A quick bit of conversion with FFmpeg, turned the results into an video file.

ffmpeg -r 60 -i frame-%04d.tif -vcodec libx264 -acodec aac -pix_fmt yuv420p -r 30 -threads 4 video.mp4

The first version simply repeated the photo for a number of frames but that gives a harsh transition between photos. A quick bit of linear interpolation and alpha blending between the two adjacent images fixed that.

int alpha = ((frameCount - (frame * framePause)) * 255) / framePause;

Alpha goes from 0 to 255, transparent to opaque. Breaking the statement down.

fadePosition = frameCount - (frame * framePause)

Gets the current position between two frames.

(fadePosition * 255) / framePause

Scale the fade position by the maximum alpha value, then divide by time frames fade over. The operations happen this way to avoid integer division rounding the framePosition/framePause to zero.

The full source code is on GitHub.

As an interesting postscript. Getting the video posted to social media proved the trickiest bit. Facebook accepted the YUV444 version of the output file but Twitter would only accept YUV420 version.