Replaygain into GNU/Linux, Calculating and writting tags into ID3v2 |
![]() ![]() |
Replaygain into GNU/Linux, Calculating and writting tags into ID3v2 |
Mar 2 2006, 12:26
Post
#1
|
|
![]() Group: Members Posts: 138 Joined: 23-December 05 Member No.: 26599 |
I'm using Linux Ubuntu 5.10 for my work desktop and most time I'm listen music under Linux. Now de'facto standard of lossy codec under Linux is Ogg Vorbis (and FLAC for loseless). Replaygain into these formats supported by many linux players. But not into mp3. I'm using MPD for playing music (daemon with control thru tcp port) and it's current svn version has support for replaygain tags into ID3v2. But only one program for linux I know with ability to calculate these tags is mp3gain and it writes info into APEv2 tag not compatible with MPD replaygain support.
I've write simple shell script for calculate ReplayGain and convert it into ID3v2 tag (mp3 file must already has ID3v2 tag). Maybe it will be usefull for someone. Calculate ReplayGain for all .mp3 files into current directory as one album. Tested only on my system. Required executables id3v2, mp3gain and eyeD3. CODE #!/bin/sh if ! which id3v2 >/dev/null; then echo "id3v2 executable not found." >&2 exit 1 fi if ! which mp3gain >/dev/null; then echo "mp3gain executable not found." >&2 exit 1 fi if ! which eyeD3 >/dev/null; then echo "eyeD3 executable not found." >&2 exit 1 fi if [[ $# > 1 || $# == 1 && $1 != "-f" ]]; then echo "Usage: `basename $0` [-f]" >&2 echo " for ReplayGain'ing all mp3 file into current directory" >&2 echo " -f -- force re-ReplayGain'ing for already ReplayGain'ed files" >&2 exit 2 fi if [[ $# == 0 ]]; then if id3v2 -l *.mp3 | egrep -qi '^TXXX .*\(replaygain_album_gain\)';then echo "Files already ReplayGain'ed." >&2 exit 1 fi fi mp3gain *.mp3 TMPFILE=`tempfile` for n in *.mp3; do mp3gain -s c "$n" > $TMPFILE mp3gain -s d "$n" TRACK_GAIN=`cat $TMPFILE|awk '/^Recommended "Track" dB / {printf("%+.2f dB", $5)}'` TRACK_PEAK=`cat $TMPFILE|awk '/^Max PCM / {printf("%.6f", $7/32768)}'` ALBUM_GAIN=`cat $TMPFILE|awk '/^Recommended "Album" dB / {printf("%+.2f dB", $5)}'` ALBUM_PEAK=`cat $TMPFILE|awk '/^Max Album PCM / {printf("%.6f", $8/32768)}'` eyeD3 \ --set-user-text-frame="replaygain_track_gain:$TRACK_GAIN" \ --set-user-text-frame="replaygain_track_peak:$TRACK_PEAK" \ --set-user-text-frame="replaygain_album_gain:$ALBUM_GAIN" \ --set-user-text-frame="replaygain_album_peak:$ALBUM_PEAK" \ "$n" done rm -f $TMPFILE Edit: change code to codebox This post has been edited by iGold: Apr 1 2006, 09:28 |
|
|
|
Mar 3 2006, 01:18
Post
#2
|
|
![]() Group: Members Posts: 123 Joined: 13-July 03 Member No.: 7751 |
Very nice. I didn't know abut eyeD3, thanks.
CODE TRACK_GAIN=`cat $TMPFILE|awk '/^Recommended "Track" dB / {printf("%+.2f dB", $5)}'` Watch out for that Useless Use Of Cat... CODE TRACK_GAIN=$(awk '/^Recommended "Track" dB / {printf("%+.2f dB", $5)}' $TMPFILE) should work just as well. |
|
|
|
Mar 31 2006, 23:34
Post
#3
|
|
|
Group: Members Posts: 2 Joined: 31-March 06 Member No.: 29048 |
Seeing as I just started rebuilding my MP3 collection, I had to run this for a LOT of discs,
The following scripts runs iGold's script recursively for you if you structure your collection like me: CODE /[Artist]/[Album]/[Files].mp3 Keep in mind my shell script skills suck and this is a quick hack, but might be helpful for someone in my situation. Before running it, cd to the root of your collection. Any improvement suggestions or syntax corrections, I'd be happy to hear them. CODE #!/bin/sh
TARGET=$1 REPLAYGAIN=/home/augusto/replaygain.sh cd "$TARGET" for artist in *; do cd "$artist" for album in *; do cd "$album" $REPLAYGAIN cd .. done cd .. done |
|
|
|
Apr 1 2006, 00:52
Post
#4
|
|
![]() Group: Members Posts: 1394 Joined: 20-December 01 From: seattle Member No.: 693 |
you might want to let us know about your fancy replaygain script for that to be exciting...
later -------------------- RareWares/Debian :: http://www.rarewares.org/debian.html
|
|
|
|
Apr 1 2006, 03:39
Post
#5
|
|
|
Group: Members Posts: 2 Joined: 31-March 06 Member No.: 29048 |
You might want to check the fancy first post of the thread, I assumed that was clear enough.
Quoting myself: "...runs iGold's script recursively for you..." |
|
|
|
Apr 1 2006, 09:25
Post
#6
|
|
![]() Group: Members Posts: 138 Joined: 23-December 05 Member No.: 26599 |
I made some changes in the script:
CODE #!/bin/sh
LC_NUMERIC=POSIX; export LC_NUMERIC MP3GAIN=`which mp3gain` if [[ $? != 0 ]]; then echo "mp3gain executable not found." >&2 exit 1 fi EYED3=`which eyeD3` if [[ $? != 0 ]]; then echo "eyeD3 executable not found." >&2 exit 1 fi if [[ $# > 1 || $# == 1 && $1 != "-f" ]] ; then echo "Usage: `basename $0` [-f]" >&2 echo " for ReplayGain'ing all mp3 file into current directory" >&2 echo " -f -- force re-ReplayGain'ing for already ReplayGain'ed files" >&2 exit 2 fi if [[ $# == 0 ]]; then $EYED3 --no-color *.mp3 \ | egrep -i '^UserTextFrame: \[Description: replaygain_album_gain\]$' >/dev/null 2>&1 if [[ $? == 0 ]]; then echo "Files already ReplayGain'ed." >&2 exit 1 fi fi $MP3GAIN *.mp3 TMPFILE=`tempfile` for n in *.mp3; do $MP3GAIN -s c "$n" > $TMPFILE $MP3GAIN -s d "$n" TRACK_GAIN=`awk '/^Recommended "Track" dB / { printf("%+.2f dB", $5) }' $TMPFILE` ALBUM_GAIN=`awk '/^Recommended "Album" dB / { printf("%+.2f dB", $5) }' $TMPFILE` TRACK_PEAK=`awk '/^Max PCM / { printf("%.6f", $7/32768) }' $TMPFILE` ALBUM_PEAK=`awk '/^Max Album PCM / { printf("%.6f", $8/32768) }' $TMPFILE` $EYED3 \ --set-user-text-frame="replaygain_track_gain:$TRACK_GAIN" \ --set-user-text-frame="replaygain_track_peak:$TRACK_PEAK" \ --set-user-text-frame="replaygain_album_gain:$ALBUM_GAIN" \ --set-user-text-frame="replaygain_album_peak:$ALBUM_PEAK" \ "$n" done rm -f $TMPFILE |
|
|
|
Sep 27 2006, 17:40
Post
#7
|
|
|
Group: Members Posts: 31 Joined: 13-August 04 Member No.: 16251 |
Which win32 tool can i use to write replaygain values that MPD understand?
(sorry bad english) |
|
|
|
Sep 27 2006, 17:48
Post
#8
|
|
![]() Group: Members Posts: 138 Joined: 23-December 05 Member No.: 26599 |
foobar2000 (and maybe new Winamp 5.3)
Edit: MPD must be at least at version 0.12.0 (released 4 days ago). This post has been edited by iGold: Sep 27 2006, 17:50 |
|
|
|
Sep 29 2006, 22:55
Post
#9
|
|
|
Group: Members Posts: 207 Joined: 17-April 02 From: Vancouver, Canada Member No.: 1807 |
foobar2000 (and maybe new Winamp 5.3) Edit: MPD must be at least at version 0.12.0 (released 4 days ago). Hey iGold, thanks for the headsup on the new MPD ReplayGain feature. I just started using MPD recently, and I love it. And I still use foobar2000 with wine for my tagging, converting, and organizing because it rocks, so it will be nice to have MPD recognizing the ReplayGain values that foobar2000 writes. -------------------- http://goweropolis.no-ip.org:8080/blog/
|
|
|
|
Sep 30 2006, 15:04
Post
#10
|
|
|
Group: Members Posts: 31 Joined: 13-August 04 Member No.: 16251 |
Thanks for info, it was nice to see that fb2k uses both cores for calculations.
|
|
|
|
Sep 30 2006, 17:28
Post
#11
|
|
|
Group: Members Posts: 131 Joined: 6-March 03 Member No.: 5359 |
Mp3's handled with mp3gain are played correctly in latest Amarok audio player. But with Ubuntu you're probably more on the Gnome side.
-------------------- A secure audio ripper for linux: code.google.com/p/rubyripper
|
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 22nd November 2009 - 11:17 |