ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
$ 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
Code:
`*.flac`
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.
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...
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.