0

So I am using ffmpeg to convert flac files from a certain folder to mp3 at 320k bitrate.

I am using this answer as a reference.

https://stackoverflow.com/a/41096234/9259505

So the command I use in Windows command shell is

ffmpeg  -i infile.flac  -c:v copy  -b:a 320k  outfile.mp3

but that is only for one song. How can I modify that command to cycle through all the .flac files in the working directory folder?

I've tried these 2 myself but they don't work.

for file in 'C:\Users\...' *.flac; do ffmpeg -i "$file" -c:v copy -q:a 0 "${file%.flac}".mp3; done

ffmpeg  -i "*.flac"  -c:v copy  -q:a 0  outfile.mp3

Note: I am using the -c:v copy because the album artwork ends up being transcoded resulting in a much bigger file which I am trying to avoid in the first place. So the command has to copy the streams.

Operating System: Windows 10

  • 1
    What operating system? Your question is missing this essential information. Please edit it. – DavidPostill Aug 16 '18 at 19:07
1

You say you are using Windows command shell, but the first command line you showed (the one that starts "for file in") doesn't look like Windows, more like some kind of Linux shell command. The second one won't work because ffmpeg won't accept a wildcard as an input file spec.

This one line Windows command does what you seem to want, to make ffmpeg (using your options above) take as its input, in turn, each flac file in the current folder and output, in the same folder, an mp3 file with the same name before the extension:

At prompt:

for %A in (*.flac) do ffmpeg  -i "%~nA.flac"  -c:v copy  -b:a 320k  "%~nA.mp3"

If the mp3 file already exists, ffmpeg will ask if you want to overwrite it.

Note: the above command is crafted for the command line. It won't work in a batch script. For that, you need to double all the percent signs (%) like this

In batch (cmd) script:

for %%A in (*.flac) do ffmpeg  -i "%%~nA.flac"  -c:v copy  -b:a 320k  "%%~nA.mp3"
  • the only working code i have found ty – MonsterMMORPG Nov 25 '18 at 13:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.