Using FFMPEG to Extract a Thumbnail from a Video

You can use the open source ffmpeg program to extract a frame to use as a thumbnail for a video. I use this for zenphoto whereby I name the jpg file as the same name as the flv video to show a thumbnail on line. The example below shows:

  • -i = Inputfile name
  • -vframes 1 = Output one frame
  • -an = Disable audio
  • -s 400x222 = Output size
  • -ss 30 = Grab the frame from 30 seconds into the video

Below is an exmple:

[tethys]:/home/rnejdl> ffmpeg -i InputFile.FLV -vframes 1 -an -s 400x222 -ss 30 OutputFile.jpg
FFmpeg version SVN-r22900-snapshot, Copyright (c) 2000-2010 the FFmpeg developers
  built on Jul 22 2010 15:02:20 with gcc 4.2.1 20070719  [FreeBSD]
  configuration: --prefix=/usr/local --mandir=/usr/local/man --enable-shared --enable-gpl --enable-postproc --enable-avfilter --enable-avfilter-lavf --enable-pthreads --enable-x11grab --enable-memalign-hack --cc=cc --extra-cflags=-msse -I/usr/local/include/vorbis -I/usr/local/include --extra-ldflags=-L/usr/local/lib --extra-libs=-pthread --disable-debug --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libdirac --disable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --disable-libopenjpeg --enable-libschroedinger --disable-ffplay --disable-libspeex --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid
  libavutil     50.14. 0 / 50.14. 0
  libavcodec    52.66. 0 / 52.66. 0
  libavformat   52.61. 0 / 52.61. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.19. 0 /  1.19. 0
  libswscale     0.10. 0 /  0.10. 0
  libpostproc   51. 2. 0 / 51. 2. 0
[flv @ 0x804a22010]Estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 24.00 (24/1)
Input #0, flv, from 'InputFile.FLV':
  Metadata:
    duration        : 306
    starttime       : 0
    totalduration   : 306
    width           : 400
    height          : 222
    videodatarate   : 255
    audiodatarate   : 59
    totaldatarate   : 321
    framerate       : 24
    bytelength      : 12292947
    canseekontime   : true
    sourcedata      : B4A7DD2A1MM1279557135136941
    purl            : 
    pmsg            : 
  Duration: 00:05:06.12, start: 0.000000, bitrate: 268 kb/s
    Stream #0.0: Video: flv, yuv420p, 400x222, 260 kb/s, 24 tbr, 1k tbn, 1k tbc
    Stream #0.1: Audio: mp3, 22050 Hz, 2 channels, s16, 8 kb/s
Output #0, image2, to 'OutputFile.jpg':
  Metadata:
    encoder         : Lavf52.61.0
    Stream #0.0: Video: mjpeg, yuvj420p, 400x222, q=2-31, 200 kb/s, 90k tbn, 24 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
frame=    1 fps=  0 q=4.8 Lsize=      -0kB time=0.04 bitrate=  -4.2kbits/s    
video:10kB audio:0kB global headers:0kB muxing overhead -100.208808%
[tethys]:/home/rnejdl>