Extract all video frames as images with FFMPEG

85,681

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:

  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
Share:
85,681
user780756
Author by

user780756

Updated on February 07, 2022

Comments

  • user780756
    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
    user780756 over 8 years
    Okay found the issue finally, it seems that Windows needs %%, as in out-%%03d.jpg
  • user780756
    user780756 over 8 years
    Yes, it's a Windows .bat file
  • Gyan
    Gyan over 8 years
    Yes, in a script, you need to escape special characters.
  • Traoré Moussa
    Traoré Moussa about 5 years
    How can I get the frames as .h264 ?
  • Zimba
    Zimba over 3 years
    to change framerate before -i, enter -framerate. To specify framerate for output after -i enter -r
  • Cristian Sepulveda
    Cristian Sepulveda about 3 years
    what is the difference between %04d and %03d?
  • JavDomGom
    JavDomGom over 2 years
    %04d -> 4 digits (0000, 0001, 0002, etc) %03d -> 3 digits (000, 001, 002, etc).
  • Zimba
    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
    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).