Batch convert .wav to mp3 and ogg?

802

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.

Share:
802

Related videos on Youtube

EKons
Author by

EKons

Updated on September 18, 2022

Comments

  • EKons
    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:

    (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
      user over 9 years
    • Arc676
      Arc676 about 8 years
      Could 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
      Maximilian Peters about 8 years
      Which OS are you using? with Ubuntu and Python2.7 or 3.5 the described problem doesn't exist.
    • EKons
      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
      niyasc about 8 years
      I'm not able to reproduce this problem neither in Fedora nor in Windows.
    • EKons
      EKons about 8 years
      @Ashafix On repl.it it exists.
    • EKons
      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
      Arc676 about 8 years
      Maybe repl has a bug?
    • EKons
      EKons about 8 years
      @Arc676 Maybe yes, maybe no. If I get an answer I will feedback again.
    • niyasc
      niyasc about 8 years
      That might be some issue with repl. Right now I don't have access to it.
    • EKons
      EKons about 8 years
      @niyasc What is repl? (Note: don't use backticks when referencing an interpreter) Also, are you on work?
    • Maximilian Peters
      Maximilian Peters about 8 years
      Seems 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
      EKons about 8 years
      @Ashafix for i in (1,2,3,4,): print(i+i+i) reproduces the error on me. (REPL)
    • EKons
      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
      Daniel about 8 years
      There error lies in the line before your for-loop. Possibly a missing ).
    • EKons
      EKons about 8 years
      @Daniel It is a tuple, it can end with a ,. That is not an error.
  • smg
    smg over 6 years
    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}"' '{}' \;
  • Anaphory
    Anaphory over 4 years
    The third example, for recursive conversion, has mismatched '.
  • qwr
    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
    Bango over 3 years
    I can confirm this works well on Windows 10
  • Oneiros
    Oneiros over 3 years
    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!""‌​"}
  • oemb1905
    oemb1905 over 2 years
    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 ;>