Contact Us

FFMPEG multiple thumbnails

Posted on 21/10/09 by Felix Geisendörfer

I'm currently implementing /video/thumbnail functionality for and did some research on how to implement it.

First I set out to create a single thumbnail which was very easy:

ffmpeg -i -vframes 1 -s 320x240 -ss 10 thumb.jpg

This takes a video file (-i and extract a single frame (-vframes 1) with 320x240px (-s 320x240) at an offset of 10 seconds (-ss 10) and saves it as thumb.jpg.

So far so good. But we actually want to offer the ability to take multiple thumbnails (like 8) in 1/8th increments of the video playtime. My initial idea was that there had to be more efficient way then calling up ffmpeg 8 times, and indeed I found one:

ffmpeg -i -r 1/10 -s 320x240 thumb_%03d.jpg

This command works the same as the one above, except that it tries to set the frame rate to 1/10 (-r 1/10 = 1 frame every 10 seconds) and saves the results as thumb_000.jpg, thumb_001.jpg, thumb_002.jpg etc. Unfortunately I could not get it to produce the exact results I wanted. I would always end up with the first frame being captured twice, and the frame rate I set would be off by 2-3 seconds.

So I hopped to IRC and asked #ffmpeg for help. Dark_Shikari (one of the crazy people who build the best video codec in the world) was kind enough to help me.

It turns out that the offset parameter (-ss) needs to be set before the input parameter (-i). That will cause ffmpeg to seek to that position in the stream *without* decoding it and in fact skipping anything but key frames! This is pretty significant as performance improved from ~20 seconds for 4 thumbnails to about 2-3 seconds.

So my final setup is pretty much like this. First I find out the video duration by running:


This gives me all kinds of useful information including the length of the video:


I then divide the length by the amount of thumbnails I need, and run a loop like this:

ffmpeg -ss $i*$interval -i -vframes 1 -s 320x240 thumb_$i.jpg

Where $i is the number of the thumb I'm extracting and $interval is the duration of the video divided by the amount of thumbs.

Works like a charm!

-- Felix Geisendörfer aka the_undefined


You can skip to the end and add a comment.

boiss said on Oct 21, 2009:


I would like to know where did you install midentify from ?

Thank you.

Felix Geisendörfer said on Oct 21, 2009:

@boiss: apt-get install mplayer

Which did put a copy of the tool in: /usr/share/doc/mplayer/examples/midentify

Let me know if that works for ya!

Henrik  said on Oct 23, 2009:

How about personal s3 buckets is there any progress on that ? :)

Felix Geisendörfer said on Oct 24, 2009:

Henrik: Yes, those will be released shortly as well. Stay tuned !

Anthony Byram  said on Nov 03, 2009:

I have a 6 second mpeg, when i tried -ss 5 it wouldn't create a thumbnail so i used -itsoffset -5 instead to get a thumbnail of 5th second. Just in case anyone else runs into this issue.

Felix Geisendörfer said on Nov 03, 2009:

Anthony Byram: what ffmpeg version is that?

Junxuan  said on Nov 03, 2009:

Hi, is may i know what is the theme that your code boxes use? I really like it as it makes it easier to read.

Anthony Byram  said on Nov 04, 2009:

@felix source was cloned from their git repo on Oct 28th then built:

FFmpeg version git-9e89b55, Copyright (c) 2000-2009 Fabrice Bellard, et al.
built on Oct 29 2009 00:30:17 with gcc 4.3.3

configuration: --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libgsm --enable-libfaac --enable-libfaad --enable-libdc1394 --disable-mmx --enable-shared --enable-gpl --enable-libgsm --enable-nonfree

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.