Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Last active December 17, 2024 15:17
Show Gist options
  • Save loretoparisi/a9277b2eb4425809066c380fed395ab3 to your computer and use it in GitHub Desktop.
Save loretoparisi/a9277b2eb4425809066c380fed395ab3 to your computer and use it in GitHub Desktop.
Extract all frames from a movie using ffmpeg
# Output a single frame from the video into an image file:
ffmpeg -i input.mov -ss 00:00:14.435 -vframes 1 out.png
# Output one image every second, named out1.png, out2.png, out3.png, etc.
# The %01d dictates that the ordinal number of each output image will be formatted using 1 digits.
ffmpeg -i input.mov -vf fps=1 out%d.png
# Output one image every minute, named out001.jpg, out002.jpg, out003.jpg, etc.
# The %02d dictates that the ordinal number of each output image will be formatted using 2 digits.
ffmpeg -i input.mov -vf fps=1/60 out%02d.jpg
# Extract all frames from a 24 fps movie using ffmpeg
# The %03d dictates that the ordinal number of each output image will be formatted using 3 digits.
ffmpeg -i input.mov -r 24/1 out%03d.jpg
# Output one image every ten minutes:
ffmpeg -i input.mov -vf fps=1/600 out%04d.jpg
@Soebb
Copy link

Soebb commented Oct 18, 2021

Is there a way to extract every 100milliseconds(1/10s) ?

@loretoparisi
Copy link
Author

@Soebb when you use 1/60 that means 1/60 frames per second, or 1 frame per 60 seconds:

ffmpeg -i input.mov -vf fps=1/60 out%02d.jpg

so to extract every 100 milliseconds it should be possibile setting the -vf fps described here:

-vf fps=fps=1/60
     ↑   ↑   ↑
     |   |   |
     |   |   |__ value
     |   |______ option
     |__________ filter

@illtellyoulater
Copy link

Is there a way to tell FFmpeg "extract ALL images composing an encoded video (regardless of frame-rate)" ?

@SirYodaJedi
Copy link

@illtellyoulater Just skip the frame rate parameters. It should look something like this:
ffmpeg -i input.mkv out%03d.png

@Sigmanificient
Copy link

@SirYodaJedi You just made my day, tysm

@reneeWhiskersScalien
Copy link

How to save all the frames extracted from one video to a folder? (Thank you)

@illtellyoulater
Copy link

@Count-MHM
Copy link

@reneeWhiskersScalien include the folder with filename:
ffmpeg -i input.mkv FOLDER\out%03d.png

@reneeWhiskersScalien
Copy link

@Count-MHM Thank you so much!

@constantm
Copy link

If you have an HDR movie, you can extract high quality images using:
ffmpeg -i HDR.mov -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p '%05d.png'

Found here

@chris1892006
Copy link

chris1892006 commented Apr 19, 2024

How to use AMD & NVIDIA hardware GPU acceleration while capturing screenshots of any given H264 or H265 video or movie? As well as add filters to make the output with anti-aliasing? Thanks

@rljhaines
Copy link

@SirYodaJedi You just made my day, tysm

...except for the fact that the statement he provides doesn't really give the result you asked for. The statement results in all instances of all images comprising the video, not simply in all images comprising the video.

@SirYodaJedi
Copy link

SirYodaJedi commented Dec 17, 2024

@SirYodaJedi You just made my day, tysm

...except for the fact that the statement he provides doesn't really give the result you asked for. The statement results in all instances of all images comprising the video, not simply in all images comprising the video.

The former is generally more useful? Yes, you'll get dupes from VFR input, but if you include the duped frames, you're able to actually reassemble the video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment