Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-23T19:40:17.613Z
Answers.LastActivityDate: 2017-01-23T19:40:17.613Z
Answers.LastEditDate: 2017-04-13T12:46:08.110Z
Answers.UserDisplayName: user3643
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-21T23:18:40.897Z
Answers.Text: For the first solution, it says `set was unexpected at this time.`
Answers.UserDisplayName: user3643
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-21T23:30:54.543Z
Answers.Text: Powershell option seems to work. Perhaps I'll just use that. Thank you.
Answers.UserDisplayName: user3643
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-22T23:49:28.393Z
Answers.Text: Dang, typo. I was on my mac so I couldnt' test it. Fixed now.
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-23T00:28:14.140Z
Answers.Text: Output file name now comes out `%outfile.mp3`. It runs, which is certainly closer, but the output file naming is not working.
Answers.UserDisplayName: user3643
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-23T11:19:06.247Z
Answers.Text: Another typo. It' been a while since I used batch scripting - I do everything in zsh and powershell. Try it again if you like, with luck it should work now..
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-23T18:47:53.747Z
Answers.Text: I'm sorry, but it still doesn't work. I'm just on the regular Windows `cmd.exe`, aka "command line". The file comes out `%outfile%`. You don't have to keep working on this if you don't want to; I'm content with the Powershell solution. If I were to guess, the `outfile` variable is not being set or called correctly, or both. Or, the `%f` in this context is not a string of the name, which is how we are trying to use it. It is a pointer to the file.
Answers.UserDisplayName: user3643
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-23T18:48:17.380Z
Answers.Text: I've asked on SO: [How to set and use filename string variables in cmd command line?](http://stackoverflow.com/q/41813473/1934286)
Answers.UserDisplayName: user3643
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-23T19:08:51.433Z
Answers.Text: The SO guys figured it out. An elegant solution. I've put in a suggested edit. The code `for %f in (*.mp4) do ffmpeg -i "%f" -vn -ar 44100 -ac 1 -b:a 32k -f mp3 "%~nf.mp3"` works.
Answers.UserDisplayName: user3643
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-21T22:38:47.603Z
Answers.LastActivityDate: 2017-01-23T22:10:02.820Z
Answers.LastEditDate: 2017-01-23T22:10:02.820Z
Answers.UserDisplayName: stib
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-01-23T07:39:51.027Z
Comments.Text: For users looking for a Linux solution see [Batch conversion into a new folder with ffmpeg](http://video.stackexchange.com/a/19862/1760).
Comments.UserDisplayName: llogan
Tags: <ffmpeg><windows>
Title: How to change output filename in ffmpeg batch?
UserDisplayName: user3643
ThreadText: # How to change output filename in ffmpeg batch?
  
  (Asked by: username_0 on 2017-01-21)
  
  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?
  
  **Tags:** ffmpeg, windows
  
  > **Comments:**
  > **username_1**: For users looking for a Linux solution see [Batch conversion into a new folder with ffmpeg](http://video.stackexchange.com/a/19862/1760).  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-01-21. Score: 5 | Accepted answer
  
  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](https://technet.microsoft.com/en-us/library/ee692804.aspx), 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")
  }
  
  ```
  
  > **Comments:**
  > **username_0**: For the first solution, it says `set was unexpected at this time.`  
  > **username_0**: Powershell option seems to work. Perhaps I'll just use that. Thank you.  
  > **username_2**: Dang, typo. I was on my mac so I couldnt' test it. Fixed now.  
  > **username_0**: Output file name now comes out `%outfile.mp3`. It runs, which is certainly closer, but the output file naming is not working.  
  > **username_2**: Another typo. It' been a while since I used batch scripting - I do everything in zsh and powershell. Try it again if you like, with luck it should work now..  
  > **username_0**: I'm sorry, but it still doesn't work. I'm just on the regular Windows `cmd.exe`, aka "command line". The file comes out `%outfile%`. You don't have to keep working on this if you don't want to; I'm content with the Powershell solution. If I were to guess, the `outfile` variable is not being set or called correctly, or both. Or, the `%f` in this context is not a string of the name, which is how we are trying to use it. It is a pointer to the file.  
  > **username_0**: I've asked on SO: [How to set and use filename string variables in cmd command line?](http://stackoverflow.com/q/41813473/1934286)  
  > **username_0**: The SO guys figured it out. An elegant solution. I've put in a suggested edit. The code `for %f in (*.mp4) do ffmpeg -i "%f" -vn -ar 44100 -ac 1 -b:a 32k -f mp3 "%~nf.mp3"` works.  
  
  ---
  
  ### Answer by username_0 on 2017-01-23. Score: 1
  
  To add to [username_2's answer](https://video.stackexchange.com/a/20475/3643), 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.
  
  
  ---
  
  