Replaygain
Posted: 09 May 2014, 06:23
I’m running Madsonic in a minimal Debian environment and have been trying for some time to get “replaygain” working. This led me to find out some other interesting things about transcoding as I fumbled my way through.
After some searching, I found that I need to read the replay gain tag (only the track gain) from my audio files. exiftool seems to be the most reliable way to do this. I created rg.sh which does my transcoding:
I ran with this for a while on both a PC and dSub on a BlackBerry Z30 (yes, I’m running an edge case here, but it does work) but periodically some items wouldn’t transcode.
It took me a great deal of trial and error to work out what was going on – in summary, any embedded cover art is read as a video stream by ffmpeg and when the filter is applied, ffmpeg gives an error. I was checking the logs, but I had turned off the verbosity in ffmpeg as well, so nothing really appeared in the Log.
In the end I had to use the –vn option to ignore any video streams. Audioffmpeg is purely for audio files and will only process the audio stream.
I hope this helps someone if they’re trying to do something similar.
After some searching, I found that I need to read the replay gain tag (only the track gain) from my audio files. exiftool seems to be the most reliable way to do this. I created rg.sh which does my transcoding:
- 1: read the ReplaygainTrackGain tag into a variable
2: use ffmpeg to filter the volume using the variable
I ran with this for a while on both a PC and dSub on a BlackBerry Z30 (yes, I’m running an edge case here, but it does work) but periodically some items wouldn’t transcode.
It took me a great deal of trial and error to work out what was going on – in summary, any embedded cover art is read as a video stream by ffmpeg and when the filter is applied, ffmpeg gives an error. I was checking the logs, but I had turned off the verbosity in ffmpeg as well, so nothing really appeared in the Log.
In the end I had to use the –vn option to ignore any video streams. Audioffmpeg is purely for audio files and will only process the audio stream.
I hope this helps someone if they’re trying to do something similar.
Code: Select all
#!/usr/bin/env sh
volume=`exiftool -a -All -s "$1" | awk '/ReplaygainTrackGain/ { print $3 }'`
echo "ReplayGain Track Gain = ${volume}dB" >&2
/var/madsonic/transcode/ffmpeg -i "${1}" -ab "${2}k" -v warning -vn -f mp3 -filter "volume=${volume}dB" -