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
  • 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?" – Stephen Harris Dec 10 '18 at 0:56
  • 1
    @StephenHarris, thanks, just working it out :-) – nath Dec 10 '18 at 0:58
  • 1
    @StephenHarris done :-))) – nath Dec 10 '18 at 1:37

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


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.

  • thanks for your reply, would you mind explaining the line? – nath Dec 16 '18 at 3:25

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.