If the JPEG encoding step is too performance intensive, you could always store the frames uncompressed as BMP images:

ffmpeg -i file.mpg -r 1/1 $filename%03d.bmp

This also has the advantage of not incurring more quality loss through quantization by transcoding to JPEG. (PNG is also lossless but tends to take much longer than JPEG to encode.)

Answer from Multimedia Mike on Stack Overflow
🌐
Gumlet
gumlet.com › learn › ffmpeg-extract-frames
How to extract frames from video using FFmpeg? - Gumlet
July 3, 2024 - In this command, "-ss 00:00:10" tells FFmpeg to start extracting frames from the 10th second of the video. As a result, you'll get frames extracted every 10 seconds throughout the video.
Discussions

python - extracting frames using FFMPEG? - Stack Overflow
Python people like JSON format, right? If that's the case then you can change -of default=nw=1:nk=0 to -of json. See FFmpeg Wiki: FFprobe Tips for more examples. You can use the select filter. Example to select one frame every ten seconds: Copyffmpeg -i -vf "select='not(mod(t\,10))'" -vsync ... More on stackoverflow.com
🌐 stackoverflow.com
I'm trying to extract a frame every 10 seconds or 300 frames from a video but I keep getting errors
from which location you launch the ffmpeg command ? %04d.png -> you will save in the folder you launched the command, maybe you can add G:\%04d.png More on reddit.com
🌐 r/ffmpeg
5
3
June 9, 2023
What is I frame extraction option every 10 sec?
Duude your skipping all frames for 10 sec then taking one frame. Try googling „ffmpeg keyframe extraction“ Edit: I got that wrong. I meant I-frames, not key-frames. More on reddit.com
🌐 r/ffmpeg
2
3
April 11, 2021
How to extract frames from a video using ffmpeg? - Video Production Stack Exchange
Basically I want to extract all frames from the video where the images will be resized to be 720p. All of this I know how to do. But for testing I want to extract every Nth frame. So every 30th image More on video.stackexchange.com
🌐 video.stackexchange.com
June 1, 2024
🌐
Stack Overflow
stackoverflow.com › questions › 35687984 › extracting-frames-using-ffmpeg › 35689725
python - extracting frames using FFMPEG? - Stack Overflow
See FFmpeg Wiki: FFprobe Tips for more examples. You can use the select filter. Example to select one frame every ten seconds: Copyffmpeg -i -vf "select='not(mod(t\,10))'" -vsync vfr output_d.png
🌐
Reddit
reddit.com › r/ffmpeg › i'm trying to extract a frame every 10 seconds or 300 frames from a video but i keep getting errors
r/ffmpeg on Reddit: I'm trying to extract a frame every 10 seconds or 300 frames from a video but I keep getting errors
June 9, 2023 -

I think this is the correct line for it:

ffmpeg -i "G:\Series\[RH] Perritos bonitos Tai [Dual Audio] [BDRip] [1080p]" -vf fps=1/10 %04d.png

But now I keep getting:

Error opening input: Permission denied

I tried running CMD as an administrator, as a normal user and adding "G:" before the line, it didn't worked.

I already tried 3 easier programs to do this but all failed, now I have to use lines of code, please help.

🌐
GitHub
gist.github.com › loretoparisi › a9277b2eb4425809066c380fed395ab3
Extract all frames from a movie using ffmpeg · GitHub
@illtellyoulater Just skip the frame rate parameters. It should look something like this: ffmpeg -i input.mkv outd.png
🌐
Creatomate
creatomate.com › blog › how-to-extract-images-from-a-video-using-ffmpeg
How to Extract Images From a Video using FFmpeg - Creatomate
October 17, 2022 - $ ffmpeg -i input.mp4 -r 1/3 framed.png The -r 1/3 argument instructs FFmpeg to extract frames every 3 seconds. To extract every 10 seconds, use -r 1/10.
Find elsewhere
Top answer
1 of 1
3

Using -r 0.1 sets the output framerate to 0.1Hz, but it's not guaranteed to get frame from the input video exactly every 10 seconds (I am not sure why).

One way for solving it is using select filter.

Example (without GPU acceleration):

ffmpeg -i input.mp4 -vf "select=bitor(gte(t-prev_selected_t\,10)\,isnan(prev_selected_t))" -vsync 0 f%09d.jpg

  • bitor(gte(t-prev_selected_t\,10) is 1 when difference between "passed" timestamps is grater of equal 10 seconds.
    When expression is evaluated to 1, the frame is "selected" and passed to the output.
  • bitor with isnan(prev_selected_t) passes the first frame, where prev_selected_t is NaN (has no value).
  • -vsync 0 applies "passthrough" - Each frame is passed with its timestamp from the demuxer to the muxer.

Here is an example with scale_cuda and thumbnail_cuda:

ffmpeg \
    -loglevel error \
    -hwaccel cuvid \
    -hwaccel_output_format cuda \
    -c:v h264_cuvid \
    -i "$video_file" \
    -filter:v "scale_cuda=w=-1:h=100,thumbnail_cuda=2,hwdownload,format=nv12,select=bitor(gte(t-prev_selected_t\,10)\,isnan(prev_selected_t))" \
    -vsync 0 \
    -color_range 2 \
    f%09d.jpg   
  • Due to the usage of thumbnail_cuda filter, we have to place the select filter at the end.

Testing:
Build synthetic video with frame counter at 10fps:

ffmpeg -y -f lavfi -r 10 -i testsrc=size=128x72:rate=1:duration=1000 -vf setpts=N/10/TB -vcodec libx264 -pix_fmt yuv420p input.mp4

Output frames after executing the above command:


As you can see, the selected frames are exactly every 10 seconds.

🌐
Medium
hansheng0512.medium.com › extract-frames-from-video-with-ffmpeg-in-one-minute-526da15090ec
Extract Frames From Video with FFmpeg in One Minute | by Liang Han Sheng | Medium
December 25, 2022 - ... You can further specify how many frames to extract per second. For example, the command below with fps=2 will extract 2 frames per second. ... And fps=1/10 will extract 1 frame per 10 seconds.
🌐
CodeGenes
codegenes.net › blog › fastest-way-to-extract-frames-using-ffmpeg
The Fastest Way to Extract Frames Using FFmpeg: Optimized Command Tutorial for Speed — codegenes.net
Result: A 1-hour 4K video (30 fps) ... in 5-10 minutes (vs 30+ minutes with the default command). For processing multiple videos, automate with a bash script. Example: Extract 1 frame/second from all MP4s in a folder: #!/bin/bash for video in *.mp4; do ffmpeg -c:v h264_cuvid -i "$video" -threads 0 -vsync vfr -r 1 -q:v 3 "${video%.mp4}_frame_d.jpg" done · For Python users, use ...
🌐
Bogotobogo
bogotobogo.com › FFMpeg › ffmpeg_thumbnails_select_scene_iframe.php
FFmpeg Scene selection : extracting iframes and detecting scene change - 2020
The advantage is that we'll get the frame at the right time, but the drawback is that it will take a lot of time until it finally reaches that time point. The bigger the seeking time is, the longer you will have to wait. - from Seeking with FFmpeg. ... Now, we want to extract thumbnails periodically. The following command will create one thumbnail image every 10 second...
🌐
Reddit
reddit.com › r/ffmpeg › what is i frame extraction option every 10 sec?
r/ffmpeg on Reddit: What is I frame extraction option every 10 sec?
April 11, 2021 -

Hello

I am trying to extract I frame every 10 sec for 24 fps video source.

Is it correct?

ffmpeg -i myvideo.mp4 -vf fps=1/600 img%03d.jpg

When it ran it, it looks like does not matched my video player timeframe.

Please correct me if I have worng.

Thanks

🌐
Stack Exchange
video.stackexchange.com › questions › 37503 › how-to-extract-frames-from-a-video-using-ffmpeg
How to extract frames from a video using ffmpeg? - Video Production Stack Exchange
June 1, 2024 - But for testing I want to extract every Nth frame. So every 30th image from a 30FPS video or every 10th image, etc. How can I do that? Also the extracted image filenames should correspond to the frame numbers so not sure if the first frame is 0 or 1? ... This will extract 1 frame per second.
🌐
OTTVerse
ottverse.com › home › ffmpeg › extract frames using ffmpeg: a comprehensive guide
Extract Frames using FFmpeg: A Comprehensive Guide - OTTVerse
August 21, 2023 - 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.
🌐
Baeldung
baeldung.com › home › scripting › extracting frames from a video using ffmpeg
Extracting Frames From a Video Using FFmpeg | Baeldung on Linux
March 18, 2024 - $ ffmpeg -i big_buck_bunny_720p_2mb.mp4 -ss 00:00:05 -r 10 -s 640x360 -q:v 2 -vframes 25 framed.jpg ... -q:v specifies the quality level of the output image, which ranges from 1 (highest quality) to 31 (lowest quality) framed.jpg specifies the output file name and format for extracted frames · The d sets the numbering used in file names to two digits, padded with zero if necessary. If we want to extract all frames after five seconds, we can run the above command without the -vframes option.
Top answer
1 of 8
131

It's very simple with ffmpeg, and it can output one frame every N seconds without extra scripting. To export as an image sequence just use myimage_%04d.png or similar as the output. The %0xd bit is converted to a zero-padded integer x digits long - the example I gave gets output as

  • myimage_0000.png,

  • myimage_0001.png,

  • myimage_0002.png

    etc..

You can use lots of still image formats, png, jpeg, tga, whatever (see ffmpeg -formats for a full list).

Ok so now we know how to export the movie as a sequence of images, but say we don't want to export every single frame?

The trick is to simply change the frame rate of the output to whatever we want using the -r n option where n is the number of frames per second. 1 frame per second would be -r 1, one frame every four seconds would be -r 0.25, one frame every ten seconds would be -r 0.1 and so on.

So to put it all together, this is how it would look to save one frame of input.mov every four seconds to output_0000.png, output_0001.png etc.:

ffmpeg -i input.mov -r 0.25 output_%04d.png

Note that the -r 0.25 option goes after the -i input.mov part, because it's controlling the frame rate of the output. If you put it before the input it would treat the input file as if it had the specified frame rate.

Change the %xd to however many digits you need, e.g. if the command would create more than 10,000 frames change the %04d to %05d. This also works for input files that are image sequence. Read more here.

Windows users: On the command line use %

example: ffmpeg -i inputFile.mp4 -r 1 outputFile_%02d.png

In CMD and BAT Scripts use %%

example: ffmpeg -i inputFile.mp4 -r 1 outputFile %%02d.png

So double %% in scripts, and single % on the interactive command line. Getting it wrong in either situation will generate an error.

Edit Worth checking out the discussion of file types in the comments below. There are advantages and disadvantages with each:

  • jpeg much smaller file sizes, lossy, only 8-bit colour, no alpha.
  • png lossless, large files, slow. 8-bit colour supports alpha.
  • tiff lossless, even larger files, fast, supports up to 16 colour and alpha.

To specify the file format, just use the required extension in the output file, e.g. myimage_%04d.jpg, myimage_%04d.png or myimage_%04d.tiff

2 of 8
36
mplayer -vo jpeg -sstep 5 file.avi

will save a frame as a jpeg file every 5 seconds.

However, it will not stop at the end of the file, it will continue producing copies of the last frame. To avoid this, find the duration of the video in seconds, using another player, or with mplayer:

mplayer -vo null -ao null -frames 0 -identify file.avi

and look for a line like "ID_LENGTH=147.00".

Subtract 2 from the length, and use this value for the -endposoption. For example, for a 147 second video:

mplayer -vo jpeg -sstep 5 -endpos 145 file.avi
🌐
Medium
medium.com › @alibugra › extract-frames-as-an-image-from-video-files-using-ffmpeg-65b52d3d97db
Extract frames as an image from video files using FFMPEG | by Ali Buğra Kanburoğlu, PhD | Medium
June 14, 2018 - By changing the “fps” parameter, output frames could be changed such as; fps=1 means every second, fps=1/60 means every minute, fps=1/600 means every ten minutes. I shared a structure that helps to extract images from video files with the ...