So I have a bunch of short videos I want to convert into images. In the past, I've used ffmpeg and .bat files to convert multiple videos from one file type to another, using two .bat files containing:

for %%F in (*.mkv) do remux_settings_.bat "%%F"


ffmpeg.exe -i %~d1%~p1%~n1.mkv -c:v copy -c:a copy %~d1%~p1%~n1.mp4

I run the latter (remux_settings_.bat) file with ffmpeg and the video files in the same folder, and ffmpeg does its job. Honestly, I don't know much about using ffmpeg - those files were given to me - so can I get a specific example of how to take this same approach for converting every frame of video into an image, e.g. .mkv to .jpg? There are other similar questions, but I'm having trouble translating the information in those answers to my situation.

  • The most basic command is: 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.
    – llogan
    Commented Apr 18, 2020 at 17:47

1 Answer 1


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


  • 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .