LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-08-2006, 09:04 AM   #1
wgato
Member
 
Registered: Jun 2006
Distribution: ubuntu slax dsl
Posts: 40

Rep: Reputation: 15
cli mp3 converter?


I've never worked with audio on linux before and I've got some foolish questions I cant seem to find an answer to.

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 ...

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
 
Old 09-08-2006, 09:20 AM   #2
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 62
http://www.linuxquestions.org/questi...d.php?t=435308
 
Old 09-08-2006, 10:31 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
Old 09-09-2006, 08:55 AM   #4
wgato
Member
 
Registered: Jun 2006
Distribution: ubuntu slax dsl
Posts: 40

Original Poster
Rep: Reputation: 15
wow, thank you very much!
 
  


Reply


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
mp3, rm converter for linux fadelhomsi Linux - Software 2 03-15-2006 03:13 AM
Mp3-Ogg converter pengu Linux - Software 4 12-22-2005 06:39 PM
mp3 2 ogg converter deftone420 Linux - Software 4 03-26-2005 04:03 AM
.rm to mp3 converter? chem1 Linux - Software 1 03-21-2004 01:12 AM
What is the best midi to mp3 converter??? Frank Linux - Software 1 07-14-2002 06:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:11 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration