Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: elf_binPosted on 2009-07-07 at 01:23:35ID: 24792313
Hi,
$FILE"
-Prog-Intr o-HOWTO.ht ml
Use the lame encoder. The command you need is:
lame --mp3input -b 256 <file_in.mp3> <file_out.mp3>
So from the command line you would cd to the directory where the files are and type:
for FILE in *
do
lame --mp3input -b 256 "$FILE" <path_to_output_directory>/"
done
What this means is for every file located in this directory, pass the file-name to lame, using the variable FILE. We place the variable in quotes to "escape" the spaces, so that the shell does not recognize the spaces in the file-names as additional parameters.
So now to place this in a shell script, create a file with the following:
#!/bin/bash
INPUT_DIRECTORY=$1
OUTPUT_DIRECTORY=$2
for FILE in $INPUT_DIRECTORY/*
do
lame --mp3input -b 256 "$FILE" OUTPUT_DIRECTORY/"$FILE"
done
This file is a shell script that starts off identifying the shell it'll use (#!/bin/bash) - this is mandatory for shell scripts and Linux supports many, many different shells.
Next, we take the parameters passed to the shell script, the first one ($1) being the source directory that you user has provided on the command line and assign it to the local variable INPUT_DIRECTORY (I do this for clarity). We then do the same for loop as we did before on the command line. There's a lot of things I've left out, such as checking that the user did provide arguments and that they are legal arguments (i.e.: real directories) and that they are readable and/or writable, or if the user swaps the location of the read and write positional arguments. Another thing to note is that if the user provides an argument such as /home/me/srcmp3/ (note the tail ending /) that would expand in the shell to for FILE in /home/me/srcmp3//* which is probably a bad idea. Another problem could be where there is a space in the directory name(s), we could just place a quote around that, but the user could pass the arguments escaping the space already and the shell would interpret as a literal (with the escaping loosing it's special meaning). Like I said, I've kept this *very* simple.
Anyway, once you've created the file, you need to make it executable, which you can do by typing chmod u+x <name_of_file>. So say we created our file as convMp3.sh we would type
chmod u+x convMp3.sh
To execute the file we would call the file (by the full path - there are other ways of doing it but I am trying to keep it simple) and pass the arguments as required, such as:
/home/me/convMp3.sh /home/me/srcmp3 /home/me/dstnmp3
This would call the script convMp3.sh located in /home/me/ with the arguments input directory: /home/me/srcmp3 and output directory: /home/me/dstnmp3
The best place (in my opinion) is to start at the bash how to, which can be accessed here: http://tldp.org/HOWTO/Bash
Hope this helps