53

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
  • 1,376
  • 3
  • 19
  • 31

4 Answers4

92

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"
Gyan
  • 85,394
  • 9
  • 169
  • 201
4

Try:

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

or

ffmpeg\ffmpeg -i file.mpg test\thumb%04d.jpg -hide_banner

Note:

  1. to change framerate before -i, enter -framerate. To specify framerate for output after -i enter -r
  2. -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
Zimba
  • 2,854
  • 18
  • 26
2

%04d will produce image-names with 4 digits like 0001, 0002 etc. And %03d will produce images with names like 001, 002 etc.

-3

Impossible to do in a windows batch file because every %x are interpreted as prameters passed to batch file

  • 5
    "Impossible" is such a harsh word... Easy to overcome: escape the `%` with another`%`: `%%x` works (as the asker already found out [7 years ago](https://stackoverflow.com/questions/34786669/extract-all-video-frames-as-images-with-ffmpeg#comment57319040_34786929)). – Stephan Feb 06 '22 at 11:21