user780756
user780756

Reputation: 1484

Extract all video frames as images with FFMPEG

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?

Upvotes: 62

Views: 149698

Answers (5)

Rafael F.
Rafael F.

Reputation: 116

You should use for native conversion/better quality:

ffmpeg -i input.mp4 -c:v png output_frame%04d.png 

See: https://ffmpeg.org/faq.html#How-do-I-encode-movie-to-single-pictures_003f

Batch script example for multiple video files:

@echo off

set ffmpeg=.\ffmpeg-6.1.1-full_build\bin\ffmpeg.exe

set pathVideos=.\pathVideos
set pathPNG=.\pathPNG

set videos=file1 file2 file3 file4

if not exist "%pathPNG%\" mkdir "%pathPNG%"

FOR %%V IN (%videos%) DO (
    %ffmpeg% -i "%pathVideos%\%%V.mp4" -c:v png "%pathPNG%\%%V_frame%%05d.png"
)

Upvotes: 1

phoenix10
phoenix10

Reputation: 1

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

Upvotes: -4

user12405848
user12405848

Reputation: 21

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

Upvotes: 1

Zimba
Zimba

Reputation: 3643

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

Upvotes: 7

Gyan
Gyan

Reputation: 92928

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"

Upvotes: 109

Related Questions