Quote:
Originally Posted by wgato
I want to convert a directory full of mp3 to a different bit rate from the command line. do you know any software that will do this? most players seem to be gui oriented ...
|
Lame is probably the most widely used MP3 encoder in the Linux world. In fact a lot of those GUI tools call it to do the actual encoding.
Quote:
Originally Posted by wgato
i am asking because i'd like to write a script that does this whenever a new file is put in a directory. i dont need to listen to the songs on the server, just convert the bit rate. will i need alot of other software? (i'm not admin on the machine) i dont know anything about what kind of soundcard it has either, does coverting the bitrate even use the soundcard?
sorry these questions are kind of odd and general, i know nothing about linux and music
|
This script will probably do more or less what you want. It'll read new files from mp3_incoming (in your home directory), and put the processed files into mp3_processed. If it encounters errors, it'll put the files which caused them into mp3_unprocessed.
Code:
#!/bin/bash
INCOMING_DIR="$HOME/mp3_incoming"
PROCESSED_DIR="$HOME/mp3_processed"
UNPROCESSED_DIR="$HOME/mp3_unprocessed"
SLEEP_TIME=5
# read the lame manual page (command: man lame) to work out
# what options you need. This example is fixed bitrate 128
# and tells lame not to output progress (which makes for
# neater output in my opinion).
LAME_OPTS="-b 128 --quiet"
for d in "$INCOMING_DIR" "$PROCESSED_DIR" "$UNPROCESSED_DIR"; do
if [ ! -a "$d" ]; then
echo "creating directory $d"
mkdir -p "$d" || exit 1
fi
done
while true; do
n=0
find "$INCOMING_DIR" -iname *.mp3 |while read f; do
echo "converting $f..."
lame $LAME_OPTS "$f" "$PROCESSED_DIR/${f##*/}"
if [ $? -eq 0 ]; then
rm -f "$f"
else
echo "WARNING - error while converting $f"
echo "file will be moved to $UNPROCESSED_DIR"
mv "$f" "$UNPROCESSED_DIR"
fi
let n+=1
done
echo "sleeping for $SLEEP_TIME seconds before next check"
sleep $SLEEP_TIME
done
To use it, save the above code to a file in your home directory called "mp3_conversion_monitor", and change the permissions so it is executable. From the terminal, the command
Code:
chmod 755 mp3_conversion_monitor
Will make it executable.
To run it just type in:
Code:
./mp3_conversion_monitor
One important caveat! You should
move files into the incoming directory,
not copy them. This is because move is an atomic (instantaneous, non-interruptable) operation. If you are in the process of copying an mp3 and lame starts to process the file before it's fully copied, you will end up with half a processed file!
You can change the attributes of the processed files by modifying the LAME_OPTS line.