Unable to call ffmpeg in a batch file
Matthew Harrington
I reencode a lot of video files with ffmpeg using the following command at the prompt:
for %F in ("..\*.*") DO ffmpeg -n -i "%F" -c:v libx265 -c:a copy "%~nF.mkv"I created a batch file containing this command and put it in my profile path. But when I run it, I get the following:
M:\>ff.bat
The following usage of the path operator in batch-parameter
substitution is invalid: %~nF.mkv"
For valid formats type CALL /? or FOR /?
The syntax of the command is incorrect.
M:\>for F" -c:v libx265 -crf 28 -c:a copy "F" -c:v libx265 -crf 28 -c:a copy "%~nF.mkv"A problem with quote marks maybe?
2 Answers
A problem with quote marks maybe?
No. it's a problem with %. On the command line use a single %. In a batch file double it up %%.
So use the following:
for %%F in ("..\*.*") DO ffmpeg -n -i "%%F" -c:v libx265 -c:a copy "%%~nF.mkv"If you are using the
FORcommand at the command line rather than in a batch program, use just one percent sign:%Ginstead of%%G.
Source: For - Looping commands - Windows CMD - SS64.com
Further Reading
- An A-Z Index of the Windows CMD command line | SS64.com
- Windows CMD Commands (categorized) - Windows CMD - SS64.com
Exactly you have to use double percentage signs instead of single. Also make sure the ffmpeg paht is in the %path% variabel of you have to specify the whole path to ffmpeg program....
1