21

I have a few hundred .wav files that I need to convert to both ogg and mp3 format. Is there a way that I can do this in batch either from Audacity or from some other command line tool?

1

5 Answers 5

32

From a Unix-like (Linux, OSX, etc) commandline, ffmpeg can be used like this:

for f in *.wav; do ffmpeg -i "$f" -c:a libmp3lame -q:a 2 "${f/%wav/mp3}" -c:a libvorbis -q:a 4 "${f/%wav/ogg}"; done

This will convert every WAV in a directory into one MP3 and one OGG; note that it's case-sensitive (the above command will convert every file ending in .wav, but not .WAV). If you want a case-insensitive version:

for f in *.{wav,WAV}; do ffmpeg -i "$f" -c:a libmp3lame -q:a 2 "${f%.*}.mp3" -c:a libvorbis -q:a 4 "${f%.*}.ogg"; done

To convert every WAV in a directory recursively (that is: every WAV in the current directory, and all directories in the current directory), you could use find:

find . -type f -name '*.wav' -exec bash -c 'ffmpeg -i "$0" -c:a libmp3lame -q:a 2 "${0/%wav/mp3}" -c:a libvorbis -q:a 4 "${f/%wav/ogg}' '{}' \;

(Max respect to Dennis for his response here for finding me a working implementation of find with ffmpeg)

For case-insensitive search with find, use -iname instead of -name.

A note on -q:a: for MP3, the quality range is 0-9, where 0 is best quality, and 2 is good enough for most people for converting CD audio; for OGG, it's 1-10, where 10 is the best and 5 is equivalent to CD quality for most people.

4
  • 6
    Very useful. I modified this to batch convert .wav to mp3 recursively, since I didn't need ogg: find . -type f -name '*.wav' -exec bash -c 'ffmpeg -i "$0" -c:a libmp3lame -q:a 2 "${0/%wav/mp3}"' '{}' \;
    – smg
    Sep 2, 2017 at 19:15
  • The third example, for recursive conversion, has mismatched '.
    – Anaphory
    Oct 27, 2019 at 12:02
  • $ for f in *.wav; do ffmpeg -i "$f" -c:a libmp3lame -b:a 320k "${f/%wav/mp3}"; done for 320 kbps mp3 only
    – qwr
    Dec 15, 2019 at 18:46
  • awesome - thanks very much, this is great - it would be nice if you would include .ogg only and .mp3 only versions in addition to the regular with both ;>
    – oemb1905
    Oct 27, 2021 at 22:22
3

You could use foobar2000 with encoders for ogg and mp3. I believe you can find encoders at rarewares.

2

Looks like you can use oggenc to convert WAV into OGG, and you can use lame to convert WAV into MP3.

2

Download ffmpeg from below link and install it: http://ffmpeg.zeranoe.com/builds/

create and run batch file with below commands in it:

echo converting *.wav to *.ogg 
mkdir ..\Ogg
for /r %%i in (*) do ffmpeg -i %%i -acodec libvorbis ..\Ogg\%%~ni.ogg

All converted *.ogg files will be copied to ..\Ogg directory.

2

I did some change to a bat file I have found on SO, it now, deals with spaces in files names as it is often the case in songs name. this bat file convert .wav to .mp3, using the VLC command line tool. But you can change to the formats wma --> mp3 and so on...

@echo off
chcp 65001
SETLOCAL ENABLEDELAYEDEXPANSION

for /f "delims=" %%f IN ('dir /b /s "YOUR_DISK:\Path\To\Your Music\That May contain Spaces\*.wav"') do (
set file1=%%~nf.mp3
echo "file :" !file1!
set fic1=%%f
echo "file : " !fic1!

CALL "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"  "!fic1!" --sout="#transcode{vcodec=none,acodec=mp3,ab=320,channels=2,samplerate=48000}:std{access=file{no-overwrite},mux=mp3,dst="""!file1!"""}" vlc://quit
)

echo .
echo conversion finished
pause

chcp change the encoding (to deal with accentuated characters.) ab is the bit rate here 320

2
  • 1
    I can confirm this works well on Windows 10
    – Bango
    Nov 13, 2020 at 19:19
  • 1
    Thank you so much, it works. I used this string in the transcode part to convert from ogg to wav: #transcode{acodec=s16l,channels=2}:standard{access=file,mux=wav,dst="""!file1!"""}
    – Oneiros
    Jan 5, 2021 at 9:37

You must log in to answer this question.