Reputation: 411
I want to convert multiple .mp4 files to .mp3 using ffmpeg. Here is what I came up with:
cd (the folder I want to use)
set counter = 1
for /r %%file in (*) (
ffmpeg %%file -i "Track %counter%.mp3"
set counter = counter + 1
)
But it didn't work. I'm guessing I made some basic syntax errors, but I can't figure out what. What did I do wrong?
Upvotes: 1
Views: 15952
Reputation: 11
@echo off
mkdir converted
for %%a in ("*.mp4") do ffmpeg -i "%%a" -b:a 192K -vn "converted\%%~na.mp3"
pause
Upvotes: 1
Reputation: 19315
the spaces are meaningful in variable assigment, except in arithmetic /a
expressions
:: more correct
set /a counter=1
:: works also because of /a
set /a counter = 1
the name of variable in for is limited to one alphabetic character a-z A-Z
for /r %f
the expansion in block (..)
is done before the for command begins, to avoid this setlocal enabledelayedexpansions
or calling a function, also using echo before command can help to debug
All together
:: cd (the folder I want to use)
set /a counter=1
for /r %%f in (*.*) do (
call :proc %%f
set /a counter=counter+1
)
:: to avoid to execute following functions
@goto :eof
:: functions
:proc
@echo ffmpeg -i %1 "Track %counter%.mp3"
@goto :eof
Upvotes: 1