How to change output filename in ffmpeg batch? I'm using windows and ffmpeg to convert video mp4 into audio mp3. I've come up with the following batch line that will do the job:

 for %f in (*.mp4); do ffmpeg -i %f -vn -ar 44100 -ac 1 -b:a 32k -f mp3 %f.mp3


However, the %f variable captures the whole filename with the extension, so my output looks like filename.mp4.mp3. I'd rather it look like filename.mp3.

I've tried all sorts of brackets and truncation methods I know of but I cannot get anything to work.

How can I change the filenames in an ffmpeg batch conversion on Windows?
You can extract the file name directly from the for replacement parameter. No need to set a new variable at all.

for %f in (*.mp4) do ffmpeg -i "%f" -vn -ar 44100 -ac 1 -b:a 32k -f mp3 "%~nf.mp3"


If you want to do more complicated string munging, it's much more intuitive in Powershell:

ls *.mp4|foreach{
    ffmpeg -i $_ -vn -ar 44100 -ac 1 -b:a 32k -f mp3 $_.name.replace("mp4", "mp3")
}