Extract all video frames as images with FFMPEG
Solution 1
Use
ffmpeg -i "%1" frames/out-%03d.jpg
A sequence of image files don't have a framerate. If you want to undersample the video file, use -r
before the input.
Edit:
ffmpeg -i "C:\Applications\FFMPEG\aa.mp4" "frames/out-%03d.jpg"
Solution 2
%04d will produce image-names with 4 digits like 0001, 0002 etc. And %03d will produce images with names like 001, 002 etc.
Solution 3
Try:
ffmpeg -i file.mpg -r 1/1 $filename%03d.bmp
or
ffmpeg\ffmpeg -i file.mpg test\thumb%04d.jpg -hide_banner
Note:
- to change framerate before
-i
, enter-framerate
. To specify framerate for output after-i
enter-r
-filter:v -fps=fps=...
or-vf fps=...
is more accurate than-r
eg.
ffmpeg -i myvideo.avi -vf fps=<NO. of images>/<per no. of seconds> img%0<padding No. of digits>d.jpg
user780756
Updated on February 07, 2022Comments
-
user780756 over 2 years
I am trying to convert a MP4 video file into a series of jpg images (out-1.jpg, out-2.jpg etc.) using FFMPEG with,
mkdir frames ffmpeg -i "%1" -r 1 frames/out-%03d.jpg
However I keep getting errors like,
[image2 @ 00000037f5a811a0] Could not open file : frames/out-C:\Applications\FFMPEG\toGIF.bat3d.jpg av_interleaved_write_frame(): Input/output error frame= 1 fps=0.0 q=5.9 Lsize=N/A time=00:00:01.00 bitrate=N/A video:63kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown Conversion failed!
If I take out the %03d part, the conversion works but it only outputs the first frame and the program stops with error.
How can I correctly extract all the frames of the video with FFMPEG?
-
user780756 over 8 yearsOkay found the issue finally, it seems that Windows needs %%, as in out-%%03d.jpg
-
user780756 over 8 yearsYes, it's a Windows .bat file
-
Gyan over 8 yearsYes, in a script, you need to escape special characters.
-
Traoré Moussa about 5 yearsHow can I get the frames as .h264 ?
-
Zimba over 3 years
-
Cristian Sepulveda about 3 yearswhat is the difference between %04d and %03d?
-
JavDomGom over 2 years%04d -> 4 digits (0000, 0001, 0002, etc) %03d -> 3 digits (000, 001, 002, etc).
-
Zimba over 2 years@CristianSepulveda: The answer to your question is in the provided code sample: "-vf fps=<
NO. of images
>/<per no. of seconds
> img%0<padding No. of digits
>d.jpg". Good job JavDomGom -
Stephan over 2 years"Impossible" is such a harsh word... Easy to overcome: escape the
%
with another%
:%%x
works (as the asker already found out 7 years ago).