2

I am making a Windows batch script with ffmpeg that can convert an audio file into multiple formats.

I want the audio to be converted in two formats here. 32kbps and 40kbps.

Setlocal EnableDelayedExpansion
for %%a in ("*.*") do ffmpeg -i "%%a" -b:a 32000 "%%~na - [email protected]" 
for %%a in ("*.*") do ffmpeg -i "%%a" -b:a 40000 "%%~na - [email protected]"
pause

However it seems I am getting three outputs.

sound - [email protected]

sound - mp3@40kbps-mp3

sound - mp3@32kbps - [email protected]

I know I must be doing something wrong here because I only want two files. Why do Why do I get a third format here (sound mp3@32kbps - [email protected]) and how can I avoid this?


This is the updated code I am using:

@echo off
for %%a in (*.*) do (   

    ffmpeg -i "%%a" -b:a 32000 -ar 44100 "%%~na - [16-bit 44,100kHz - 32kbps].mp3" 
)
pause
2
  • Sorry I don't use ffmpeg, and I guess the problems are related to your sourcefile and the changed options not the batch file as such. Commented Nov 13, 2016 at 16:37
  • Thanks for all your help, but the error says converter.bat: Invalid data found when processing input which means that ffmpeg has found something wrong with the batch file, not the audio file. Commented Nov 13, 2016 at 16:44

1 Answer 1

3

The second for loop also processes the newly generated mp3 from 1st for. Better use only one for:

Setlocal EnableDelayedExpansion
for %%a in (*.*) do (   
  ffmpeg -i "%%a" -b:a 32000 "%%~na - [email protected]" 
  ffmpeg -i "%%a" -b:a 40000 "%%~na - [email protected]"
)
pause
Sign up to request clarification or add additional context in comments.

6 Comments

For some reason this gives me Invalid data found when processing input: i.imgur.com/GzQJ4Ax.png This is the code I am using i.imgur.com/UAzw5ol.png
@Arete without knowing your exact code or the input file it's quite dificult to say anything about it. I used your *.* which isn't a good idea cause it takes every possible extension. You should change that to mp3 or whatever your source looks like. And if my answer is coorrect I would be glad if you checked that big green mark accordingly. Cheers
I have added the code I am using to the question. As for which file format I am trying to convert the result is the same.. It can be WAV, mp3 or any other audio format
@Arete This is the correct answer to solve the original issue you were experiencing, so this answer should be accepted. Now you are encountering another, separate issue. As mentioned already the *.* is greedy and is using the script file itself as an input.
@LordNeckbeard Thanks. What does "*.*" do? I tried searching but couldn't find anything :/
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.