Extracting JPG Frames Using FFmpeg
Jan 12
I recently posted abut pulling PNGs from video files using FFmpeg. Since then I’ve received a few emails about doing the same for JPGs as well as exporting files at a certain frame. While I’ve figured out to achieve the former, I’m completely baffled with the latter. To extract the jpg frame you can use the following command:
ffmpeg -i swing.avi -s 320×240 -vframes 1 -f singlejpeg swing.jpg
This is fairly straightforward. The next hurdle is to figure out how to export an image at a certain frame or time. The command above exports the first frame of the movie, yet it would be nice to specify frame nnn and have it exported. I’m working on several parameter combinations and will hopefully post a winner over the weekend.

I am using the latest version of ffmpeg
libavutil version: 49.0.0
libavcodec version: 51.8.0
libavformat version: 50.4.0
on Unix
When I use: ffmpeg -i swing.avi -s 320×240 -vframes 1 -f singlejpeg swing.jpg
I get:
Unknown input or output format: singlejpeg
If I subsitute ‘mpjpeg’ for ‘singlejpeg’ I get a .jpg file that is not readable by any browser such as IE or Firefox or even Windows Paint.
Have you encountered this issue and have a solution.
The Solution is:
ffmpeg -i swing.avi -s 320×240 -vframes 1 -f mjpeg swing.jpg
instead of:
ffmpeg -i swing.avi -s 320×240 -vframes 1 -f singlejpeg swing.jpg
Try:
ffmpeg -i swing.avi -s 320×240 -vframes 1 -f image2 swing.jpg
or
ffmpeg -i swing.avi -s 320×240 -vframes 1 -f image2 -vcodec mjpeg swing.jpg
I also figured that, if you want to capture a frame other than the 1st frame, you can use the -ss parameter. e.g.
ffmpeg -i swing.avi -s 320×240 -ss 5 -vframes 1 -f image2 swing.jpg
will capture the frame 5 seconds into the movie.
btw, does anyone know what the -vframes param used for? I tried changing it to a larger value, like -vframes 10. all it does it enlarge the jpeg file size, but not capturing more frames. what’s the deal?
http://www.movo9.com – Mobile TV + Video
Ben,
Thanks for the info on the ss parameter. From my understanding the vframes parameter allows you to specify a number of frames that you want to grab from the video. I’ve yet to successfully use the parameter, but will definitely play around with it.
BTW, I’m a huge fan of your Bluelet library and was working to port my BlueGPS (http://www.db75.com/bluegps) to Java a while back. Here’s a proto of what I had running the Bluelet library:
http://www.db75.com/new_blog/?p=73
Keep up the great work!
Dennis
When I use “-vframes” option, it gives me error:
——–
ffmpeg: unrecognized option ‘-vframes’
———
root@… [/home/tmhitsc/www/temp]# ffmpeg -version
ffmpeg version 0.4.9-pre1, build 4718, Copyright (c) 2000-2004 Fabrice Bellard
built on Nov 15 2006 10:40:32, gcc: 3.4.6 20060404 (Red Hat 3.4.6-3)
ffmpeg 0.4.9-pre1
libavcodec 4718
libavformat 4616
What do you think it could be? I also don’t get sound when converting to FLV format, picture is OK and it gives me no error, I am converting from mpg, but just no sound:((
Can you post the exact syntax you’re using? You should be able to use vframes with your current version. Also, I’m not sure about the sound problem but you can see an example of a video I encoded here:
http://www.db75.com/new_blog/?p=132
I am using syntax listed above here. I am really confused with all these – it just doesn’t work.
# ffmpeg -i n.wmv -s 320×240 -vframes 1 -f singlejpeg swing.jpg
ffmpeg version 0.4.9-pre1, build 4718, Copyright (c) 2000-2004 Fabrice Bellard
built on Nov 15 2006 10:40:32, gcc: 3.4.6 20060404 (Red Hat 3.4.6-3)
Input #0, asf, from ‘n.wmv’:
Duration: 00:06:37.6, bitrate: 102 kb/s
Stream #0.0: Audio: wmav2, 16000 Hz, mono, 16 kb/s
Stream #0.1: Video: wmv2, 320×240, 1.00 fps
ffmpeg: unrecognized option ‘-vframes’
I also tried this thing here, but no success. It just created a black jpg file – and command wasn’t executed completely – look at the error:
root # ffmpeg -i n.wmv -f singlejpeg -img jpeg -y test.jpg
ffmpeg version 0.4.9-pre1, build 4718, Copyright (c) 2000-2004 Fabrice Bellard
built on Nov 15 2006 10:40:32, gcc: 3.4.6 20060404 (Red Hat 3.4.6-3)
Input #0, asf, from ‘n.wmv’:
Duration: 00:06:37.6, bitrate: 102 kb/s
Stream #0.0: Audio: wmav2, 16000 Hz, mono, 16 kb/s
Stream #0.1: Video: wmv2, 320×240, 1.00 fps
Output #0, singlejpeg, to ‘test.jpg’:
Stream #0.0: Video: mjpeg, 320×240, 1.00 fps, q=2-31, 200 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Press [q] to stop encoding
[wmv2 @ 0x8267b98]I7:0/
[wmv2 @ 0x8267b98]I7:2/
[wmv2 @ 0x8267b98]I7:9/
[wmv2 @ 0x8267b98]I7:2A/
[wmv2 @ 0x8267b98]J-type picture isnt supported
Error while decoding stream #0.1
frame= 4 q=1.6 Lsize= 21kB time=4.0 bitrate= 42.1kbits/s
video:21kB audio:0kB global headers:0kB muxing overhead 0.000000%
I copied this sample video for you, please try and see if you can transform it -
http://tmhits.com/n.wmv
Thanks,
muhammed
Hi Muhammed,
Thanks for encouraging me to look into this again. Please see the following post:
http://www.db75.com/new_blog/?p=315
Thanks,
Dennis