user3643: 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?

user3643: To add to stib's answer, you can also put this command in a simple batch file. Just save the code below into a .bat file, move the file to the folder you want to work on, then double click it to run. This is assuming you've downloaded and set up ffmpeg.
@echo off
title Extract MP3 from MP4 with FFMPEG. 
rem Mono Channel, 32kbps.
for %%f in (*.mp4) do ffmpeg -i "%%f" -vn -ar 44100 -ac 1 -b:a 32k -f mp3 "%%~nf.mp3"
pause

Notice that the %f variables are now %%f. This is a batch file convention and is required. The script will not run if this is not changed. title is exactly that: the title of the script. rem is short for "remark": it is a comment and you can change that too. Neither lines are actually necessary.

user1950: 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")
}


3643: <p>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:</p>

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

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

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

<p>How can I change the filenames in an ffmpeg batch conversion on Windows?</p>
 3643: <p>To add to <a href="https://video.stackexchange.com/a/20475/3643">stib's answer</a>, you can also put this command in a simple batch file. Just save the code below into a <code>.bat</code> file, move the file to the folder you want to work on, then double click it to run. This is assuming you've downloaded and set up ffmpeg.</p>

<pre><code>@echo off
title Extract MP3 from MP4 with FFMPEG. 
rem Mono Channel, 32kbps.
for %%f in (*.mp4) do ffmpeg -i "%%f" -vn -ar 44100 -ac 1 -b:a 32k -f mp3 "%%~nf.mp3"
pause
</code></pre>

<p>Notice that the <code>%f</code> variables are now <code>%%f</code>. This is a batch file convention and is required. The script will not run if this is not changed. <code>title</code> is exactly that: the title of the script. <code>rem</code> is short for "remark": it is a comment and you can change that too. Neither lines are actually necessary.</p>
 1950: <p>You can extract the file name directly from the <code>for</code> replacement parameter. No need to set a new variable at all.</p>

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

<p>If you want to do more complicated <a href="https://technet.microsoft.com/en-us/library/ee692804.aspx" rel="nofollow noreferrer">string munging</a>, it's much more intuitive in Powershell:</p>

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