Batch convert .wav to mp3 and ogg?
Solution 1
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.
Solution 2
You could use foobar2000 with encoders for ogg and mp3. I believe you can find encoders at rarewares.
Solution 3
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
Solution 4
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.
Solution 5
Looks like you can use oggenc to convert WAV into OGG, and you can use lame to convert WAV into MP3.
Related videos on Youtube
EKons
Updated on September 18, 2022Comments
-
EKons over 1 year
Note: This question is about a problem with repl.it, not a general problem.
Note: You might consider this as a duplicate, but in fact it isn't.
These do not suit my problem:- Python unexpected EOF while parsing : syntax error
- Python unexpected EOF while parsing
- Unexpected EOF while parsing in python
- Python unexpected EOF while parsing (python2.7)
(Taken from alerady answered questions list, duplicates excluded for compactness)
I've got a problem with for loops in Python (repl.it Python 2 and Python 3 interpreters) in that one-line for loops without a trailing newline raise
SyntaxError
.for i in (1,2,3,4,): print i+i+i
Traceback (most recent call last): File "python", line 1 for i in (1,2,3,4,): print i+i+i ^ SyntaxError: unexpected EOF while parsing
for i in (1,2,3,4,): print i+i+i # Trailing newline
3 6 9 12
Another question: How to display a trailing newline , trailing space or unprintable character in SE (without using <pre>)?
-
user over 9 years
-
Arc676 about 8 yearsCould you provide some more details about your system? I'm on a Mac, Python 2.7.10 and I can't reproduce this issue. I've tried writing this to a file and just using the interpreter, but both run just fine.
-
Maximilian Peters about 8 yearsWhich OS are you using? with Ubuntu and Python2.7 or 3.5 the described problem doesn't exist.
-
EKons about 8 years@Arc676 I've said I'm using it on repl.it so you could give it a try there (Updated recently to Python 2.7.10 'cause of my feedback).
-
niyasc about 8 yearsI'm not able to reproduce this problem neither in Fedora nor in Windows.
-
EKons about 8 years@Ashafix On repl.it it exists.
-
EKons about 8 years@niyasc As I've replied to others, I'm using repl.it, so you could give it a try there.
-
Arc676 about 8 yearsMaybe repl has a bug?
-
EKons about 8 years@Arc676 Maybe yes, maybe no. If I get an answer I will feedback again.
-
niyasc about 8 yearsThat might be some issue with
repl
. Right now I don't have access to it. -
EKons about 8 years@niyasc What is
repl
? (Note: don't use backticks when referencing an interpreter) Also, are you on work? -
Maximilian Peters about 8 yearsSeems to be repl specific. When using repl.it/languages/python3 the error is reproduced, one liner via the command line works or entering the function in python3 on Ubuntu works as well.
-
EKons about 8 years@Ashafix
for i in (1,2,3,4,): print(i+i+i)
reproduces the error on me. (REPL) -
EKons about 8 years@Ashafix The header line 2
[GCC 4.8.2] on linux
tells me it is compiled with GCC on a Linux OS, written in C/C++. -
Daniel about 8 yearsThere error lies in the line before your for-loop. Possibly a missing
)
. -
EKons about 8 years@Daniel It is a tuple, it can end with a
,
. That is not an error.
-
smg over 6 yearsVery 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}"' '{}' \;
-
Anaphory over 4 yearsThe third example, for recursive conversion, has mismatched
'
. -
qwr over 4 years
$ for f in *.wav; do ffmpeg -i "$f" -c:a libmp3lame -b:a 320k "${f/%wav/mp3}"; done
for 320 kbps mp3 only -
Bango over 3 yearsI can confirm this works well on Windows 10
-
Oneiros over 3 yearsThank 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!"""}
-
oemb1905 over 2 yearsawesome - 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 ;>