LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-06-2007, 12:13 PM   #1
hacker supreme
Member
 
Registered: Oct 2006
Location: As far away from my username as possible
Distribution: Gentoo
Posts: 259
Blog Entries: 1

Rep: Reputation: 30
BASH script for converting ogg to mp3.


Yes, I know that there have been other threads with similar subjects but none seem to have the outcome that I am looking for.

What I would like to do is convert my entire (all 2.5GBs) music collection to mp3 so that I can play them on my media player.
(I looked at the stats. It only plays the proprietry formats, boo.)

Oh, and I'm trying to avoid using Audacity to convert them one by one and manually edit the ID3 tags.
 
Old 07-06-2007, 01:19 PM   #2
dawkcid
Member
 
Registered: May 2007
Location: UK
Distribution: LFS,Slackware,Slamd64,NetBSD
Posts: 102

Rep: Reputation: 15
You can use oggdec to decode ogg files to raw PCM, then pipe that into an mp3 encoder (lame, etc.). You'll probably need to specify the sample rate and bitwidth manually (44100KHz, 16-bit, or whatever). Something like,

Code:
#!/bin/sh
for f in "$(find "$@" -name "*.ogg")"; do
        oggdec -R -b 16 -e 1 -o - $f | lame --verbose -r -m j -s 44.1 --bitwidth 16 - ${f%.*}.mp3
done
Feed it a directory (or list or directories) and it'll convert all the ogg files in that tree. (Well, it should....) You might need to play with the options a bit if your samples aren't at 44100/16-bit etc.

edit:
You may or may not need the '-e 1' option to oggdec. This swaps the endiannesss of the output. -e 1 uses big endian output, I found that I need this (on x86), presumably lame assumes big endian input (the man page doesn't specify). If the output file is just noise, then remove this option.

Last edited by dawkcid; 07-06-2007 at 01:28 PM.
 
Old 07-06-2007, 01:54 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Only 2.5gb? I've ripped about 60 gigs of oggs already from my cd collection, and I still have about a hundred disks to go.

Check out soundconverter. It can convert several formats and keep the tags. It can be used in cli batch mode or from it's gui. You'll need lame and the gstreamer-lame plugin for mp3 support.

I should warn you though. the last time I tried it, for some reason the mp3 tags it generated wouldn't display in either easytag or audiotagtools. Probably an id3 version problem or something. They showed up just fine in audacious and konqueror (with the metadata plugin) though.

BTW, it bears repeating that converting from one lossy format to another always means some level of sound degradation. Re-ripping from the original media is recommended for best quality.

Oh yeah, one more thing. Some no-brand mp3 players can play .ogg files, even if it's not stated as such on the box. If you're player is one like that, you might want to test it out.
 
Old 07-06-2007, 02:45 PM   #4
hacker supreme
Member
 
Registered: Oct 2006
Location: As far away from my username as possible
Distribution: Gentoo
Posts: 259
Blog Entries: 1

Original Poster
Rep: Reputation: 30
Hmmm... I'll have to check if it'll play OGG. If it does I'll let you know.

Yes! It does play OGG files. (I should've checked earlier.)
Saves me a whole lotta trouble.

And David, yeah I've only got 2.5GB of music, I don't often have the money to go out and buy CDs, etc.

Last edited by hacker supreme; 07-06-2007 at 03:09 PM.
 
Old 06-30-2009, 02:39 PM   #5
sumdog
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 0
Lightbulb OGG 2 MP3 Script

I wanted to do the same thing, plus I wanted to maintain my OGG meta data (convert it to ID3 tags). I created the following script:

http://penguindreams.org/scripts/oggfolder2mp3/

It does a folder at a time, and places it in a destination (e.g. if you select "/media/music/Radio Head - Kid A" as the source and "/tmp/convert" as the destination, it will created a new folder called "/tmp/convert/Radio Head - Kid A" and place the mp3s in it)

You can place calls to the script in a for loop to take care of all your directories.

-Sumit
 
  


Reply

Tags
conversion, mp3, ogg, proprietary


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting .ogg to .mp3? servnov Linux - General 8 03-06-2014 03:21 PM
Bash mp3 to ogg script True`Colors Programming 6 07-20-2007 09:54 AM
Converting cda to mp3 OR ogg Cyb3rKnyght Linux - Software 2 10-18-2004 08:41 PM
converting from ogg to mp3 adee Linux - Newbie 4 04-04-2004 03:05 PM
Converting mp3 to ogg schatoor Linux - Software 8 07-07-2003 12:58 AM


All times are GMT -5. The time now is 01:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration