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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-24-2004, 05:13 PM
|
#1
|
|
Member
Registered: Sep 2003
Distribution: Debian testing/unstable
Posts: 225
Rep:
|
quick bash script to convert flac to mp3
I was wondering if someone could give me a hand at writing a quick bash script to convert some .flac's to .mp3's so I can play them on my palm pilot. Right now all I have is:
Code:
flac -sdc $1 | lame - $2
Which as you can see is very limiting. I would like to be able to convert a while directory with something like: sh convert.sh /dir/full/of/flac and have it place the file's in the current directory.
Ultimately, I would like it to compose the file name from the previous file and the two top directories because my file structure is like so: artist/album/songs.flac, so the finished file would look like: artist-album-song.mp3
If I wasn't so busy with school I would read the bash coding how-to, but for now if someone could get my started that would be great. I also think this would benefit others, because of right now it seems to be sort of a pain in the ass to convert flac's to mp3's. Hell, I had to dig outside the debian repositories just to install lame.
|
|
|
|
11-24-2004, 05:28 PM
|
#2
|
|
Senior Member
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197
Rep:
|
Re: quick bash script to convert flac to mp3
Quote:
Originally posted by zuralin
I was wondering if someone could give me a hand at writing a quick bash script to convert some .flac's to .mp3's so I can play them on my palm pilot. Right now all I have is:
Code:
flac -sdc $1 | lame - $2
Which as you can see is very limiting. I would like to be able to convert a while directory with something like: sh convert.sh /dir/full/of/flac and have it place the file's in the current directory.
|
Code:
#!/bin/sh
cd $1
for S in *.flac; do
flac -sdc ${S} | lame - ${S%.flac}.mp3;
done
Quote:
Ultimately, I would like it to compose the file name from the previous file and the two top directories because my file structure is like so: artist/album/songs.flac, so the finished file would look like: artist-album-song.mp3
|
I'm too lazy to look up the shell variable that contains the path. I generally break out perl when I want something more complex than a for loop anyway.
Quote:
If I wasn't so busy with school I would read the bash coding how-to, but for now if someone could get my started that would be great. I also think this would benefit others, because of right now it seems to be sort of a pain in the ass to convert flac's to mp3's. Hell, I had to dig outside the debian repositories just to install lame.
|
Welcome to GPL hell. It seems to be catching...
|
|
|
|
11-24-2004, 06:39 PM
|
#3
|
|
Member
Registered: Sep 2003
Distribution: Debian testing/unstable
Posts: 225
Original Poster
Rep:
|
Very cool, thank you very much
|
|
|
|
03-08-2009, 08:41 AM
|
#4
|
|
Member
Registered: Sep 2004
Location: Romania
Distribution: Ubuntu, Debian, Arch Linux, Gentoo, Slackware
Posts: 171
Rep:
|
Quirk ;-)
This didn't work for me.
Using:
Code:
$ bash --version
GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
But it did after I found out that doesn't escape spaces and other chars, then I enclosed the file names in double quotes.
This works perfectly for the current folder full of flac files, which will be copy-converted to file.mp3 instead.
Code:
#!/bin/sh
for S in *.flac; do
flac -d -F --totally-silent -c "${S}" | lame -ms -q0 -V0 -B192 --resample 44.1 - "${S%.flac}.mp3";
done
Put it inside a file in the flac's folder and run it like "sh convert.sh" or "chmod u+x convert.sh; ./convert.sh"
Thanks for the initial script!
Note the extra arguments to the lame encoder. They are just for better conversion and slightly better quality. It just uses the best (slowest) algorithms and goes for a 192kbps VBR MP3. The mod is also set to Stereo (not Joint Stereo) for personal reasons; you can remove the -ms flag if you want to. My main target for this conversion was to play my files on a car FM MP3 player.
|
|
|
|
03-09-2009, 02:05 PM
|
#5
|
|
Member
Registered: Mar 2009
Posts: 40
Rep:
|
Cool script Worksman ... Thanks!

Last edited by sureshsujatha; 03-14-2009 at 12:18 AM.
|
|
|
|
03-14-2009, 03:51 PM
|
#6
|
|
Member
Registered: Sep 2004
Location: Romania
Distribution: Ubuntu, Debian, Arch Linux, Gentoo, Slackware
Posts: 171
Rep:
|
Quote:
Originally Posted by sureshsujatha
|
It's not even remotely "cool". It even makes me fell embarrassed to receive a compliment like that for such a lame mixture of command line parameters and pipes... I've been meaning to learn some real Bash'ing...
|
|
|
|
03-14-2009, 10:42 PM
|
#7
|
|
Senior Member
Registered: May 2005
Posts: 4,397
|
FWIW, one tool can be used for conversion instead of two: flac + lame - as simple as
ecasound -i file.flac -o file.mp3
.
|
|
|
|
03-15-2009, 10:56 AM
|
#8
|
|
Member
Registered: Sep 2004
Location: Romania
Distribution: Ubuntu, Debian, Arch Linux, Gentoo, Slackware
Posts: 171
Rep:
|
I doubt that is as flexible as using the two tools option.
Besides, I could go as far as to say that everyone prefers lame for their mp3 encoding needs.
No bashing intended.
|
|
|
|
08-19-2011, 03:50 AM
|
#9
|
|
Member
Registered: May 2011
Distribution: Slackware 13.37
Posts: 38
Rep:
|
Code:
#!/bin/sh
for S in *.flac; do
flac -d -F --totally-silent -c "${S}" | lame -ms -q0 -V0 -B192 --resample 44.1 - "${S%.flac}.mp3";
done
it's not that bad: but could be tweaked to this:
Code:
#!/bin/sh
for S in *.flac; do
flac -d -F --totally-silent -c "${S}" | lame -V2 --vbr-new --resample 44.1 - "${S%.flac}.mp3";
done
Edit: Note!! use lame 3.97 to achieve best quality!
Last edited by slacktroll; 08-19-2011 at 04:03 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:03 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|