I have a bunch of short videos I want to convert into images.
As already mentioned by @llogan in the comments, the basic ffmpeg
command to extract images from an input file is e.g.:
ffmpeg -i input output_%04d.jpg
where:
input
an the input file (often a .gif
or video file).
%04d
represents the zero-padding/numbering sequence for the output files (so ex. output_0001.jpg
, output_0002.jpg
, output_0003.jpg
, etc.)
So for .mkv
files specifically, this would then be ex.:
ffmpeg -i input.mkv output_%04d.jpg
Multiple Video Files
To do this with multiple video files, you could use any number of approaches, even with a Windows batch file. However, the simplest solution might be to use the Windows forfiles utility, like so:
forfiles /s /m *.mkv /c "cmd /c ffmpeg -i "@FILE" output_%04d.jpg"
In essence, forfiles
allows you to run a one-line command on individual files in a repeated fashion. In this case:
/s
means to recurse sub-directories (so files in sub-folders will be affected).
/m
is a file mask (in this case, all files with the .mkv
extension).
/c
is the command to run:
cmd /c
opens a new cmd
(command window) instance. This helps overcome a bug in later versions of forfiles.
ffmpeg -i "@FILE" output_%%04d.jpg
is the ffmpeg
command to run on a given file. @FILE
is an automatic variable generated by forfiles
corresponding to name of the file currently being processed.
The outer set of double quotes (""
) prevents forfiles
from complaining about /c
being specified twice, while the inner set of double quotes (""
) around @FILE
are there in case the file name itself contains spaces.
Note that a path to the files you wish to process with forfiles
can be specified with the /p
option (assuming forfiles
isn't being run in the root directory you wish to affect).
Batch File
Be aware that if you want to place the given forfiles
command in a batch file, you will need to double the percent signs (%
) used in the ffmpeg
command:
ex. video_2_images.bat
forfiles /s /m *.mkv /c "cmd /c ffmpeg -i "@FILE" output_%%04d.jpg"
This is a standard requirement when using percent signs (%
) in Windows batch files.
ffmpeg -i input output_%04d.jpg
. See the image muxer documentation for details. I am not a Windows user so I can't help with the batch-file part of your 2-in-1 question.