1

I was looking for a .bat script for ffmpeg and came across this thread on the forum here.

The code in question is

for %%F in (*.mp4) do (
If not Exist "%%~nF" MkDir "%%~nF"
ffmpeg -i %%F -r 1 -qscale:v 2 %%~nF\%%~nF-%%3d.jpg
)

FFMPEG is added to PATH, when I try to use this batch script on a folder the folders are created but no images appear.

In addition to getting the screenshots to appear in the folders, I'd just like to know if there's a better command for including multiple file formats - most of my content is in .mkv but here are random other formats as well.

would

for %%F in (*.mp4, *.mkv) do (

work for that?

I forgot to add, I'm not sure if it matters but the files are on external hard drives (not C:/), the script ran from within the folder that contains the files.

My apologies for creating a new post, I would have commented in that one and hoped for the commenter to respond, but I am a new account and didn't have the reputation. Any help is greatly appreciated, thank you for your time!

1 Answer 1

0

The line with ffmpeg of the copied code is not save for path/filenames containing spaces.

Change the ffmpeg-line to the following:

ffmpeg -i "%%F" -r 1 -qscale:v 2 "%%~nF\%%~nF-%%3d.jpg"

Please note the added quotations.


I'd just like to know if there's a better command for including multiple file formats - most of my content is in .mkv but here are random other formats as well.

would

for %%F in (*.mp4, *.mkv) do (

work for that?

Why don't you test this known code by yourself? Testing this is absolutely trivial. Questions you easily can solve by yourself is not polite. — It prohibits us to help others.

But yes: To catch different file formats by their extension, the simplest change to the code is your own suggestion.


Update

Unfortunately I changed the line but it's still closing immediately and nothing is appearing in the folders

This hints to me that you start the batch by a shortcut icon, but not from within an open command shell.

To see the code working, please open a command shell and start the script as a shell command. PLease copy the output as an update to your question.

Perhaps you want to generate a small test structure of your video collection to limit to a reasonable amount of output.

6
  • Thank you for responding. I wasn't able to test if it worked because I was unable to get any of the screenshots working in the first place :^) Since I was here I figured another related question wouldn't have been an issue, over cluttering up with multiple junk posts. Commented Jul 6, 2023 at 23:04
  • Thank you again for responding! I really appreciate it. Unfortunately I changed the line but it's still closing immediately and nothing is appearing in the folders. for "%%F" in (*.mkv, *.mp4) do ( If not Exist "%%~nF" MkDir "%%~nF" ffmpeg -i "%%F" -r 1 "%%~nF\%%~nF-%%3d.png" ) Commented Jul 6, 2023 at 23:11
  • Updated the answer.
    – dodrg
    Commented Jul 6, 2023 at 23:42
  • Hi there, I've just found some time to go and take a look at this some more. Unfortunately, I've not made any headway whatsoever - the only information I get from using CLI is "%%F: No such file or directory", or "%%F" was unexpected at this time. Commented Jul 14, 2023 at 18:54
  • It may be a permissions error due to the files being on an external hard drive. Will try on C:/ Edit: It did not matter, same result via CLI. Commented Jul 14, 2023 at 19:02

You must log in to answer this question.

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