LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 11-20-2006, 03:14 PM   #1
kmasaryk
LQ Newbie
 
Registered: May 2004
Distribution: Ubuntu, RHEL, OS X
Posts: 23

Rep: Reputation: 15
cmd line prog to convert mp3 samplerate


Anyone know of a command line prog. which will allow me to convert the sample rate of an mp3? e.g. I'd like to convert a file from 48000 Hz to 44100 Hz.

Thanks
 
Old 11-20-2006, 04:36 PM   #2
gabor
LQ Newbie
 
Registered: Nov 2006
Posts: 13

Rep: Reputation: 0
try the sox program
 
Old 11-20-2006, 05:13 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I think pretty much any of the available programs will do. Lame is pretty easy:

lame --mp3input --resample 44.1 -b 192 inputfile.mp3 outputfile.mp3

The hardest part is the id3 tags. I don't know of any program that will copy them over from the old file to the new one. The best thing I can suggest is to make sure the output file name has all of the important tag info, then use audiotagtool or some other id3 editor to "tag based on filename".
 
Old 11-24-2006, 03:45 PM   #4
kmasaryk
LQ Newbie
 
Registered: May 2004
Distribution: Ubuntu, RHEL, OS X
Posts: 23

Original Poster
Rep: Reputation: 15
I wrote a nice solution to my problem and thought I'd post it here in case anyone else might find it useful. I created a script to do a sampling rate conversion (but you could easily do other conversions with it) while preserving the ID3 tag info.

This script relies on an excellent program called mp3info to extract tag and technical info and then lame for the conversion.

If your on Ubuntu, you can do a
Code:
apt-get install mp3info
from the universe but you'll need to d/l and compile lame yourself (annoying but easy).

Code:
#! /bin/bash

for f in *.mp3; do
    rate=`mp3info -p "%q" "$f"`

    if [[ $rate != "44" ]]
	then
	title=`mp3info -p "%t" "$f"`
	track=`mp3info -p "%n" "$f"`
	artist=`mp3info -p "%a" "$f"`
	album=`mp3info -p "%l" "$f"`
	year=`mp3info -p "%y" "$f"`
	genre=`mp3info -p "%g" "$f"`
	comment=`mp3info -p "%c" "$f"`

	lame --resample 44.1 --tt "$title" --tn "$track" --ta "$artist" \
	    --tl "$album" --ty "$year" --tg "$genre" --tc "$comment" \
	    "$f" "$f.out"
	
	mv -f "$f.out" "$f"
    fi
done
 
Old 11-25-2006, 12:05 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Nice, easy little script there. But I see two problems.

1. mp3info only works with id3v1 tags. If the file has id3v2 tags they will be ignored. This is especially a problem if it ONLY has id3v2. You may have to find another program to get your id3 info with.

2. I've discovered that lame will revert to the default 128kbs bitrate unless you specify it during recording. So if you have higher bitrate files you'll need to find some way to read that from the origin file and transfer it over as well.

Otherwise, nice work.
 
  


Reply



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
a linux prog to convert mpeg to Divx/xvid?? zeltak Linux - Software 1 04-22-2006 03:35 AM
cmd line send attachment? jedimastermopar Linux - General 2 06-16-2005 12:51 PM
Convert video mode from 32 to 24 using text login in CMD (no gui) ? HELP !!! jalalmn Linux - General 6 03-19-2005 05:06 AM
mp3 batch convert, remote from command line zerodot Linux - Networking 1 02-12-2003 05:08 AM
a prog for burning mp3 on cd safrout Linux - Software 28 12-20-2002 12:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 03:44 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
Open Source Consulting | Domain Registration