Creating contact sheets with FFmpeg

Preparing video files for Discourse or FB can create challenges that delay or discourage sharing. Viewing high quality video not only requires an investment of time, but also consideration of loss due to compression. A contact sheet provides an economization of time and file size when used as a companion or substitute for long format video.

Once well understood, this process takes just a few minutes in post depending on the length of the source file.

This process utilizes the open source command line applications FFmpeg and ImageMagick. These applications can be installed with Homebrew.


FAQ:

  • Will this work on my operating system?

From FFmpeg’s About:

FFmpeg is the leading multimedia framework, able to decode , encode , transcode , mux , demux , stream , filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.

From ImageMagick’s Home:

Use ImageMagick to create, edit, compose, or convert digital images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, GIF, WebP, HEIC, SVG, PDF, DPX, EXR and TIFF. ImageMagick can resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.

The current release is ImageMagick 7.1.0-19. It runs on Linux, Windows, Mac Os X, iOS, Android OS, and others.


Installing Homebrew, FFmpeg, and ImageMagick:

If your operating system does not come with FFmpeg or ImageMagick already installed, Linux, Windows 10, and Mac users can use Homebrew to install both.

  • Homebrew can be installed with the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  • FFmpeg and ImageMagick can then be installed with the following commands:

brew install ffmpeg
brew install imagemagick


Creating Contact Sheets with video frames from FFmpeg:

Once a video clip has been captured, it can be converted into a time lapse contact sheet in the following way:

  • Navigate in terminal to the folder containing your video file.

  • Use FFmpeg to extract stills from your video file at a user defined rate:

ffmpeg -i input.mov -vf fps=1/1 -q:v 1 output%02d-1fps.png

  • Use ImageMagick to montage extracted stills into a contact sheet:

montage -geometry 720x486 *.png sheet-output-1fps.png


Basic adjustment of parameters:

The above commands extracted stills at a rate of 1 frame every 1 second and montaged them on a sheet named sheet-output-1fps.png.

  • The following commands will extract stills at a rate of 1 frame every 5 seconds and montage them on a sheet named sheet-output-1every5.png.
ffmpeg -i input.mov -vf fps=1/5 -q:v 1 output-1every5%02d.png
montage -geometry 720x486 *.png sheet-output-1every5.png


  • If for instance, I wanted this montage to conform to a single column or to a single row:

montage -tile 1x -geometry 720x486 *.png sheet-output-1col.png


montage -tile x1 -geometry 720x486 *.png sheet-output-1row.png



References:

8 Likes

ffmpeg is really just such a wonderful tool. I need to get my stuff together and do a stream/release my ffmpeg video cookbook

thank you for putting this together

5 Likes

I could create an ffmpeg cookbook too. I’ve built a set of bash scripts which use ffmpeg as a backend. Some of them are by now quite complex and powerful tools, which names like videobubble, videomirror and videopublish. Others are much simpler in function, but use a lot of code (most of it sanity checking). A few are just weird novelties, like videobars and videorings. I can use any of them as starting points for new tools.

The names make it easy for me to find the “recipies” in my cookbook, but I use a few of them for routine everyday video processing, like videoutility, which can perform many different functions in a processing pipeline, so they can easily be combined. They can all document themselves.

$ videoutility --help
videoutility [OPTIONS] INPUT [OUTPUT]
Process a video using various ffmpeg filters.

Options:
–help|-h Display this help
–debug|-d Debugging command. Display ffmpeg command
–test|-t Same as --debug
–hue HUE Rotate hue by HUE
–sat SAT Rotate saturation by SAT
–cycle RATE Cycle hue rotation every RATE seconds
–swapuv Swap hue and saturation planes
–negate|-h Negate all planes (except alpha)
–technicolor Apply ‘technicolor’ effect
–vflip Flip vertically
–hflip Flip horizontally
–noflash Adjust for epileptic photosensitivity
–reverse Reverse video (warning: done in memory)
–rotate RATE Rotate clockwise every RATE seconds
–crop X:Y:W:H Crop using the rectangle provided
–vga VGA format
–pal|-p PAL format
–ntsc|-n NTSC format
–hd720|-hd HD720 format
–hd1080 HD1080 format
–size|-s SIZE Scale size to WxH (defaults HD720)
–start START Start at time START in seconds (defaults to 0)
–length LENGTH Output has duration LENGTH in seconds (defaults to length of input file)
–volume VOLUME Scale volume by VOLUME

Arguments:
INPUT Input video filename. Required.
OUTPUT Output video filename. Required.

Environment:
FFMPEG Override pathname for ffmpeg.

Exit Status:
Unreliable. Whatever ffmpeg returns. I.e. always success.
Only internal errors return a failure.

6 Likes

I have nothing to add but this excites me