Create an Image Preview from a Video

By  on  

Visuals are everything when it comes to media.  When I'm trying to decide whether to watch a video on Netflix, it would be awesome to see a trailer of some kind, but alas that isn't available.  When I'm looking to download a video on my computer, it'd be awesome to have one single, condensed preview image which has thumbnails of every {x} seconds/minutes of the video to see whether it's worth watching.  I was sniffing around to find an app or easy way to do it but couldn't find anything, but I did find a way to use two utilities, ffmpeg and ImageMagick, so complete the task.  Let's go!

Use ffmpeg to Take Screenshots at Set Intervals

You have to view the ultimate task at hand in two steps:  create all the screenshots and then join them together.  ffmpeg is the best utility to take screenshots on intervals:

# Take a screencap every second
./ffmpeg -i jack-slow.mpeg -vf fps=1 video-caps/cap%d.png

# Take a screencap every minute
./ffmpeg -i jack-slow.mpeg -vf fps=1/60 video-caps/cap%03d.png

# Take a screencap every ten minutes
./ffmpeg -i jack-slow.mpeg -vf fps=1/600 video-caps/cap%04d.png

Depending on the length of video, you'll want to use one of the preceding shell command formats.  You may want to do the math (in your head or programmatically) to check video length and create a given number of thumbnails, but creating individual screenshots is the first step.

Use ImageMagick to Merge Images

While ffmpeg is great for video manipulation, ImageMagick is its image counterpart.  Joining images into one is incredibly easy:

# Append images vertically "-append"
convert video-caps/*.png -append video-caps/all.png

# Append images horizontally "-append"
convert video-caps/*.png +append video-caps/all.png

I love that joining images horizontally or vertically is as simple as one character and that I can use a wildcard to set the source directory and images. Here is a source video and example output:





If you want to open the image in your default image viewer, try this:

# Open with the default app
open all.png

# Open with a specific app
open -a /Applications/ all.png

The above works well on Mac -- if you don't use a Mac...good luck, I'm you'll need to figure out what works best on your OS.

The only hard part of setting this up is installing ImageMagick and ffmpeg, and then figuring out your image intervals.  There are probably more presentable ways to create these thumbnails but that's surely more involved.  Happy screening!

Recent Features

  • By
    Create Namespaced Classes with MooTools

    MooTools has always gotten a bit of grief for not inherently using and standardizing namespaced-based JavaScript classes like the Dojo Toolkit does.  Many developers create their classes as globals which is generally frowned up.  I mostly disagree with that stance, but each to their own.  In any event...

  • By
    How to Create a Twitter Card

    One of my favorite social APIs was the Open Graph API adopted by Facebook.  Adding just a few META tags to each page allowed links to my article to be styled and presented the way I wanted them to, giving me a bit of control...

Incredible Demos

  • By
    Sexy Album Art with MooTools or jQuery

    The way that album information displays is usually insanely boring. Music is supposed to be fun and moving, right? Luckily MooTools and jQuery allow us to communicate that creativity on the web. The XHTML A few structure DIVs and the album information. The CSS The CSS...

  • By
    Scrolling “Go To Top” Link Using Dojo

    One of the most popular code snippets of posted on my blog has been the scrolling "Go To Top" link snippet. The premise of the snippet is simple: once the user scrolls an element (usually the BODY element) past a given threshold, a "Go...


    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!