Creating video thumbnails using ffmpeg

Generating thumbnails/screenshots of a video is useful in many ways. Youtube and many other video sites use this to show a preview of the video as a small thumbnail. Google video captures a series of thumbnails from a video at various time intervals to show a better video preview.

There is a simple way to generate thumbnails in Linux using ffmpeg, a very very useful tool for processing videos. Let us generate a thumbnail for this video. Download the video and rename it to test.avi.

Then, run this command,

ffmpeg  -itsoffset -4  -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg



This command generates a 320×240 sized PNG thumbnail at the 4th second in the video. The output looks like this.
video thumbnail

If you do not have ffmpeg installed and are using Debian/Ubuntu, do,

sudo apt-get install ffmpeg



A series of thumbnails, at 4, 8, 12 and 16 seconds.
video thumbnail
video thumbnail
video thumbnail
video thumbnail

ffmpeg  -itsoffset -4  -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
ffmpeg  -itsoffset -8  -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
ffmpeg  -itsoffset -12  -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
ffmpeg  -itsoffset -16  -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg



useful links

Happy thumbnailing!

3 Trackbacks

  1. [...] Creating Video Thumbnails using FFmpeg (for -itsoffset) [...]

  2. [...] Create Video Preview Thumbnails with Ffmpeg VN:F [1.2.3_620]please wait…Rating: 0.0/10 (0 votes cast)See http://blog.prashanthellina.com/2008/03/29/creating-video-thumbnails-using-ffmpeg/ [...]

21 Comments

  1. aris

    how if my filename is with space instead?!
    ex: my video.avi

    thanks for reply

    Posted April 13, 2008 at 6:49 am | Permalink
  2. Try enclosing the filename in double quotes like this –> “my video.avi”

    Posted April 13, 2008 at 7:42 am | Permalink
  3. aris

    still no effect..
    i trying to upload
    $filePath = $uploadDir.$fileName;

    ffmpeg -i “.$filePath.” -y -s 320×240 -ab 32000 -ar 22050 -g 160 -cmp 3 -subcmp 3 -mbd 2 -flags aic+cbp+mv0+mv4+trell “.$convPath

    where $filePath is source path where files is already uploaded.
    upload is successfull but when ffmpeg start to conversion i got no files at $convPath.but vice versa if i use filename with no spaces instead.

    Posted April 13, 2008 at 7:53 am | Permalink
  4. The command you posted here is missing a ” at the end. When the command runs, does it throw any errors?

    Posted April 13, 2008 at 6:48 pm | Permalink
  5. mike

    Using “-ss” rather than “-itsoffset” is considerably faster. e.g. ffmpeg -ss 12 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320×240 test.jpg

    Posted May 20, 2008 at 11:35 pm | Permalink
  6. Thanks for the info, Mike.

    Posted June 1, 2008 at 10:34 pm | Permalink
  7. sagar

    Hi, is there any possibility to create thumbnails in windows environment

    Posted July 17, 2008 at 10:24 am | Permalink
  8. Sagar, I have not tried it, but I think ffmpeg can be compiled for windows.

    Posted July 17, 2008 at 8:43 pm | Permalink
  9. sagar

    Thanks Prashanth Ellina…

    Posted July 18, 2008 at 9:39 am | Permalink
  10. Roger

    if you canot instal ffmpeg on the server is there another option to generate thumbnails on linux

    Posted October 13, 2008 at 11:00 pm | Permalink
  11. @mike , Very useful command , thanks .

    Posted November 23, 2008 at 10:52 pm | Permalink
  12. dong

    It is not work on Linux

    Posted December 12, 2008 at 12:32 pm | Permalink
  13. dong

    Help?? Please make it work on Linux

    Posted December 12, 2008 at 12:35 pm | Permalink
  14. Mariana

    Sorry, I can creat video thumbnails using ffmpeg when the video is in other server????? for example:
    ffmpeg -itsoffset -4 -i http://www.otherserver.com/test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320×240 http://www.myserver.com/test.jpg

    Posted February 26, 2009 at 8:36 pm | Permalink
  15. shashi k. sharma

    Hi
    is it possible to execute the following command on server1 and the video is situated at server two and we want to create thumbnail at server 3
    ffmpeg -itsoffset -16 -i server2/home/test/test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320×240 server3/home/test/test.jpg

    Posted April 24, 2009 at 5:19 pm | Permalink
  16. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    $myphoto = “user/”.$v.”/photo/”.$rname[0].”.jpg”;

    exec (“ffmpeg -itsoffset -4 -i “.$target_path.” -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320×240 “.$myphoto);

    when i run this command in photo directory there is no thumbnails …….
    when i run this command on command prompt as
    ffmpeg -itsoffset -4 -i life.jpg -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320×240 life.flv
    errors comes as…….
    could not find codec parameters
    when i run this command on command prompt as
    ffmpeg -itsoffset -4 -i life.flv -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320×240 life.jpg
    again errors comes as…….
    could not find codec parameters

    Posted May 14, 2009 at 12:45 pm | Permalink
  17. sree

    instead of extracting one image,can i extract a number of images in a single line command(not using loop)?

    Posted June 29, 2009 at 4:20 pm | Permalink
  18. vipin

    hi i want to extract(thumbnails) images from video in equal interval im using ffmpeg for image extraction but i dont know how to generate images in equal interval is there any shell script to fulfill this operation (E.G. suppose that i uploaded a video and i dont know the length of the video and it extracts 5 images from the video in equal interval )

    please help

    Posted August 10, 2009 at 11:58 am | Permalink
  19. Evan

    If you’re trying to do this server side and you have physical access to the server, you can run ffmpeg directly from the CLI using exec().

    Posted August 14, 2009 at 4:20 pm | Permalink
  20. dilton

    I’ve been trying to create video thumbnail file using wampserver. I managed to install ffmpeg but I don’t know how to use in my script. I’m new to php. please any suggestion. Thank in advance

    Posted September 3, 2009 at 4:28 pm | Permalink
  21. Sean

    It works! thanks

    Posted December 26, 2009 at 3:52 pm | Permalink