Extract Frames using FFmpeg: A Comprehensive Guide

As someone working with FFmpeg for my research or consulting projects, I’ve faced the need to extract frames from videos. Whether you need to grab the first frame, extract all frames, or get an exact frame with a specific timestamp, FFmpeg has you covered. 

Today, I’d like to share how you can extract frames using FFmpeg – with the respective commandlines.

extract frames using ffmpeg

Extract Frames Using FFmpeg – basic Command

Okay – let’s dive into frame extraction directly. Here is the most basic command line to extract frames using FFmpeg. 

The following command line will extract one frame for every second of the video. So, if your video is 1 minute long, you will have 60 PNG images in your folder where you ran this command. 

ffmpeg -i input.mp4 -vf "fps=1" frame%04d.png

Here’s what each element does:

  • -i input.mp4: This parameter specifies the input file, which is ‘input.mp4’ in this case. You replace ‘input.mp4’ with the name of your video file.
  • -vf "fps=1": The `-vf` stands for video filter. Here, we are specifying a filter of “fps=1”, which means we are extracting a frame per second from the video.
  • frame%04d.png: This part of the command is the output. The %04d is a placeholder that increments for each output frame, beginning from 1. So the frames will be saved as frame0001.png, frame0002.png, and so on.

It’s worth noting that the output frames are in PNG format, which is lossless and maintains the original quality. 

You can, however, specify other formats like JPEG if you prefer. All you need to do is to change the file type to “jpg” or “jpeg”; FFmpeg will save the output in the JPEG compression format.

In the next section, I’ll show you how to control the quality of a JPEG image. 

Frame Extraction to JPEG Format

To maintain the original quality of the frames extracted, you should use a lossless format like PNG images, as we showed in the previous section. 

However, PNG files can become quite large when dealing with high-resolution videos. 

A workaround for this is to use the JPEG format but with the quality set to the maximum. The following command accomplishes this:

ffmpeg -i input.mp4 -q:v 1 frame%04d.jpg

The -q:v 1 argument sets the quality of the output image. The quality value can range from 1 (highest quality) to 31 (lowest quality). For JPEG output, the filesize is inversely proportional to the quality value, meaning a lower quality value results in a larger file size.

Related:  FFmetrics - Free testing tool to measure video quality

Okay, now, it’s quite likely that you don’t want to extract a frame for every second of the video. Maybe you want to extract only the 1st frame, right? In the next section, let’s learn how to do just that.

Extracting the First Frame of a Video using FFmpeg

Moving on to a more specific case, let’s look at how you can extract the first frame from a video using FFmpeg. 

This command is handy in instances where you need a thumbnail or a preview of the video.

The command to achieve this is:

ffmpeg -i input.mp4 -frames:v 1 output.png

The -frames:v 1 argument does all the hard work here. It tells FFmpeg to stop after extracting one video frame. 

Note that the order matters; if you put -frames:v 1 before -i input.mp4, it will not work correctly.

FFmpeg: Extracting All Frames to PNG

In some situations, you might need to extract all frames from a video. FFmpeg makes this task straightforward with the following command:

ffmpeg -i input.mp4 frame%04d.png


This command is quite similar to the basic frame extraction command we discussed earlier, with one difference – we’ve omitted the -vf "fps=1" parameter. The omission means FFmpeg will extract every frame, not just one per second.

But be careful with this command.

If you have a 1-hour video shot at 60 fps, you’ll end up with 60 mins * 60 seconds * 60 frames/second = 216000 PNG images in your folder – instantaneously! 

I accidentally ran this command on a 3-hour test clip, and my drive was FILLED to the brim with extracted images! So, don’t use this command lightly or without considering the size of the output first 🙂 

Extracting a Frame with an Exact Timestamp

Lastly, let’s address a slightly more complex scenario – extracting an exact frame at a specific timestamp. The following command does just that:

ffmpeg -ss 00:01:00 -i input.mp4 -frames:v 1 output.png

The -ss 00:01:00 part is what makes this command different. It instructs FFmpeg to seek forward to the 1-minute mark of the video. The format is HH:MM:SS. 

Remember, you can modify the timestamp to meet your exact needs. The -frames:v 1 argument ensures that only one frame is extracted at the specified timestamp.

That’s it, folks – that is all I have for you today in our FFmpeg tutorial. I have written much on this subject, so feel free to explore OTTVerse’s extensive FFmpeg tutorials

krishna rao vijayanagar
Krishna Rao Vijayanagar

Krishna Rao Vijayanagar, Ph.D., is the Editor-in-Chief of OTTVerse, a news portal covering tech and business news in the OTT industry.

With extensive experience in video encoding, streaming, analytics, monetization, end-to-end streaming, and more, Krishna has held multiple leadership roles in R&D, Engineering, and Product at companies such as Harmonic Inc., MediaMelon, and Airtel Digital. Krishna has published numerous articles and research papers and speaks at industry events to share his insights and perspectives on the fundamentals and the future of OTT streaming.

Leave a Comment

Your email address will not be published. Required fields are marked *

Enjoying this article? Subscribe to OTTVerse and receive exclusive news and information from the OTT Industry.