Skip to content

Instantly share code, notes, and snippets.

@tkaemming
Created July 1, 2009 16:17
Show Gist options
  • Save tkaemming/138853 to your computer and use it in GitHub Desktop.
Save tkaemming/138853 to your computer and use it in GitHub Desktop.

Creating Video Thumbnails with FFmpeg

Assuming you have FFmpeg (http://ffmpeg.org/) installed, you should be able to run the following command. (It helps to have ffmpeg on your path, or call it absolutely from your script.)

ffmpeg -y -i ./path/to/video.mpg -f mjpeg -ss 00:00:05 -vframes 1 ./path/to/thumbnail.jpg

Hints:

  • The -f flag forces the output to "mjpeg". You can view a list of available formats by with "ffmpeg -formats".
  • The -ss flag denotes the position in the video (HH:MM:SS[.xxx] format). I'm sure there's a way to get the total length of the video (if you're doing video conversions before this, you should be able to get it by parsing STDERR).
  • The -vframes 1 flag forces a single frame to be output.
  • You can do a lot of other really cool things with FFmpeg, most which I probably don't know about. The documentation for the FFmpeg command line invocation syntax is here: http://ffmpeg.org/ffmpeg-doc.html#SEC7
  • I think you can redirect either stream to/from STDOUT/STDIN by replacing the filename with "--" (no quotes). That way, you can pipe it directly into a file-like object, if that's where you're ultimately going to be going, but need to do some resizing before saving, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment