Batch convert (decode) audio into multiple formats with ffmpeg
Solution 1
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
Solution 2
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.
Related videos on Youtube
Comments
-
nath over 1 year
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
-
Stephen Harris over 5 yearsTake 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?"
-
nath over 5 years@StephenHarris, thanks, just working it out :-)
-
nath over 5 years@StephenHarris done :-)))
-
-
nath over 5 yearsthanks for your reply, would you mind explaining the line?