CLI one-liners: batch exporting video frames

So, let’s say you just downloaded all the session videos from a certain Mac System Administrators conference:

You add these files to your media centre for easy viewing. Of course, you’re using Plex cause you’re a cool cat who’s in the know. But what’s this? The generated thumbnails are a rather random assortment. Can it not see the effort that Tycho & Co. have put into each video’s opening?

What, me? Suck up to  @gregneagle ? Well, maybe…

These would make for much better ‘posters’. In order to extract these frames, we’re going to use MPlayer — a free and open source media player. It handles just about all formats, is infinitely configurable and its man ‘page’ is actually 145 pages*.

If you don’t already have MPlayer, the easiest way to install it is via Homebrew:

$ brew install mplayer

Now, on to the actual command:

Let's go through it piece by piece.

  • -nosound — Pretty self-explanatory. Don't worry about audio (saves some processor time).
  • -really-quiet — This time, not about audio. Surpresses the console output (it’s a very chatty command without this).
  • -vo png — Use video output driver png. In other words, convert frames into PNG files. Followed by a list of parameters for said driver (separated by :).
  • z — PNG compression level. Hardly noticed a difference, so I cranked it to 9 (maximum).
  • outdir — Specify a directory to save the PNG files to (otherwise dumped in the current working directory).
  • -ss (not shown) — Seek to a given time position (e.g. -ss 60 take frame(s) from 1 minute into the video).
  • -frames — The number of frames to export. We only need 1.

At the command line, navigate to the folder where your video files are located, run that bad-boy and check your ~/Pictures folder for the results.

After adding these assets to Plex, we see a noticable improvement.

* No exaggeration (US Letter). Try: $ man -t mplayer >