3

I have a directory with a bunch of CD quality (16bit 44100Hz) wave-files.

How can I batch decode those into different formats (lets say FLAC, OGG and MP3) using ffmpeg?


Update: here are the commands one by one as suggested by @StephenHarris

ffmpeg -i input.wav output.ogg
ffmpeg -i input.wav output.mp3
ffmpeg -i input.wav output.flac
3
  • 2
    Take it step by step. How would you convert one file? If you can work out how to convert one wav file into flac, into ogg, into mp3 (3 separate commands) then we can add a loop around it. So "what command would you use to convert wav to flac?" "what command would convert wav to ogg?" "What command would convert wav to mp3?" Dec 10, 2018 at 0:56
  • 1
    @StephenHarris, thanks, just working it out :-)
    – nath
    Dec 10, 2018 at 0:58
  • 1
    @StephenHarris done :-)))
    – nath
    Dec 10, 2018 at 1:37

2 Answers 2

3

ffmpeg accepts multiple output formats. Set the input file.format with -i followed by the output file.format: ffmpeg -i input.wav output.ogg output.mp3 output.flac


Batch conversion:

As a simple one liner with putting each format in a separate folder:

mkdir mp3 ogg flac; for i in *.wav; do ffmpeg -i "$i" -b:a 320000 "./mp3/${i%.*}.mp3" -b:a 320000 "./ogg/${i%.*}.ogg" "./flac/${i%.*}.flac"; done

Decode all into one folder:

for i in *.wav; do ffmpeg -i "$i" -b:a 320000 "${i%.*}.mp3" -b:a 320000 "${i%.*}.ogg" "${i%.*}.flac"; done

-b:a 320000 sets the bitrate for the decoding of mp3 and ogg and can be adjusted (the bitrate is measured in bits/sec so 320kbit/s equals 320000).


thanks to https://stackoverflow.com/a/33766147 for the parameter-expansion

3

Using GNU Parallel you can run:

parallel ffmpeg -i {1} {1.}.{2} ::: *.wav ::: ogg mp3 flac

{1} = replacement string for first input source
{1.} = replacement string for first input source with extension removed
{2} = replacement string for second input source
::: *.wav = input source 1
::: ogg mp3 flac = input source 2

This will use all your cores.

2
  • thanks for your reply, would you mind explaining the line?
    – nath
    Dec 16, 2018 at 3:25
  • whoa...this is the way Feb 11, 2021 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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