Hi! Thanks for visiting my blog. If you've received any value from my content would you mind supporting my new startup by downloading our browser add-on? It's called PriceBlink and makes online shopping a breeze. You can watch it in action here and download it for Chrome, Firefox, IE, or Safari by going to PriceBlink.com. Thank you and I hope you enjoy!

Extracting Video Frame at Specific Time Using FFmpeg

Dec 03

This post is LONG overdue. I’ve been playing FFmpeg for a long time now and through trial and error, along with this page, figured out how to extract a JPG frame from a video at a specific time. A reader recently posted a question asking how to get this done and I hope he doesn’t mind me posting a frame grab here:

test.jpg

This came from a Windows Media file and was grabbed using the following command:

ffmpeg -i n.wmv -ss 00:00:20 -t 00:00:1 -s 320×240 -r 1 -f singlejpeg myframe.jpg

If you haven’t seen FFmpeg’s overwhelming parameter list then beware. This might look like a complicated command, but given FFmpeg has over 100 parameters this really isn’t much. Here’s what the parameters mean:

-i input file name
-ss set the start time offset
-t set the recording time
-s set frame size (WxH or abbreviation)
-r set frame rate (Hz value, fraction or abbreviation)
-f force format

The last paramter is actually the output file name. I can’t tell you how excited I am to finally get this working. If you have any problems with the command above then please be sure to contact me.

8 comments

  1. Emilio /

    This command doesn’t work neither linux debian nor windows server 2003.
    But if you change the -f force format to this->

    ffmpeg -i %1 -ss 00:00:20 -t 00:00:01 -s 320×240 -r 1 -f mjpeg %2.jpg

    it will be work.
    You article was very useful for me.
    Best regards :-)
    Emilio

  2. If you’re a PHP fan, there’s always ffmpeg-php which does it all for you ;-)

    http://ffmpeg-php.sourceforge.net/

  3. Hi, I got here through this post http://lists.mplayerhq.hu/pipermail/ffmpeg-user/2006-July/003526.html

    I just wanted to add how I was able to get a few frames (it’s hard to get the right one on the first try) with this:

    ffmpeg -ss 0:1:36 -t 1 -i movie.avi -f image2 image-%d.png

    It uses the movie size and grabs 1 second (-t 1) worth of png images into image-1.png, image-2.png, etc. Depending on the encoding, you might get 24 or 30 images or something else.

  4. I got it working in a perl script that produces one png shot at any time:

    ffmpeg -ss 0:10:00 -t 1 -s 400×300 -i input.avi -f mjpeg output.png

    I am running ubuntu.

  5. Is there any way in which I can get the frame size of every encoded frame as output in a text file ?

    I am using the following command:
    ffmpeg -i -g 500 -bf 0 -qscale 30 2> “test.txt”

    Using the above command, I am able to generate a text file with frame size of intermediate frames only, whereas I wish to have the sizes of all frames.

    How do I do that ? Please help. I am running on Ubuntu.

  6. **the command is :
    ffmpeg -i input -g 500 -bf 0 -qscale 30 outputfilename 2> “test.txt”

  7. Just be aware that it isn’t “precise” because it can only start a split at a keyframe.

  8. can any one help me how to extract the I and P frames of a video and how the we could recognize whether it is I or P?

Leave a Reply