0
votes

I'm converting webm to mp4 using FFmpeg.

My batch file is

cd "C:\Users\Matt\Desktop\" && for %f in (*.webm) do ffmpeg -y -i "C:\Users\Matt\Desktop\%~f" -vcodec libx264 -b:v 600K -pass 1 -acodec aac -b:a 128k "C:\Users\Matt\Desktop\%~nf.mp4" && ffmpeg -y -i "C:\Users\Matt\Desktop\" -vcodec libx264 -b:v 600K -pass 2 -acodec aac -b:a 128k "C:\Users\Matt\Desktop\%~nf.mp4"

It works for CRF and 1 Pass, but using 2 Pass it stops on the second pass and gives the error:

C:\Users\Matt\Desktop" -vcodec libx264 -b:v 600K -pass 2 -acodec aac -b:a 128k C:\Users\Matt\Desktop\video: Invalid argument

The first double quote is missing on the Path, and the filename "video 01.mp4" is cut off.

1
Are you certain that the -i parameter in the second pass is correct? The other two times you've used it, you've specified a file. In the last instance, it appears to be a directory - possibly the terminal \" is being interpreted as an escaped-"Magoo
@Magoo You're right, the second Path is missing %~f. That solved it, thanks.Matt McManis
2-pass means that the output of the first pass is used as input for the second one, right?aschipfl
@aschipfl I'm not sure now. On the wiki it shows the original source being used as the input for both passes. trac.ffmpeg.org/wiki/Encode/H.264#twopassMatt McManis
Ah, I see. You should rather trust the documentation than me, I do not really know ffmpeg, it just appeared more logical to me the way I said, but the tool seems to work differently (I guess there is a temporary file somewhere holding the information gathered during the first pass). Sorry for confusing you!aschipfl

1 Answers

2
votes

Your code could only work in cmd directly, in a batch you have to double the percent signs of the for variable.
There is no need for a one liner in a batch.
I hope this is more clear and works.

@Echo off
Pushd "C:\Users\Matt\Desktop\"
for %%f in (*.webm) do (
  ffmpeg -y -i "%%~f" -vcodec libx264 -b:v 600K -pass 1 -acodec aac -b:a 128k -f mp4 NUL 
  ffmpeg -y -i "%%~nf_tmp.mp4" -vcodec libx264 -b:v 600K -pass 2 -acodec aac -b:a 128k "%%~nf.mp4"
)
PopD
Pause