Volume Normalization

Got an idea? Missing something? Post your feature request here.

Moderator: moderators

can't figure out how to do this

Postby DJC » Tue May 10, 2011 6:52 pm

I've tried, but I don´t understand the transcoding command lines. So if this is what I have in flac to mp3:

Step 1: ffmpeg -i %s -v 0 -f wav -
Step 2: lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -

How should the command using reply gain look like? Thanks in advance.

Daniel
DJC
 
Posts: 11
Joined: Sat Apr 30, 2011 7:25 pm

Re: Volume Normalization

Postby feather333 » Wed Oct 05, 2011 7:45 pm

Can anyone tell me if Replay Gain can be used for video files as well as audio files? I would need to use it for wmv, flv, f4v and mp4. I'm hoping to be able to adjust just the audio on a great number of files with the minimum of hassle and without having to re-encode anything.

Thanks.
feather333
 
Posts: 1
Joined: Wed Oct 05, 2011 7:41 pm

Re: Volume Normalization

Postby BKKKPewsey » Fri Oct 07, 2011 6:35 pm

feather333 wrote:Can anyone tell me if Replay Gain can be used for video files as well as audio files? I would need to use it for wmv, flv, f4v and mp4. I'm hoping to be able to adjust just the audio on a great number of files with the minimum of hassle and without having to re-encode anything.

Thanks.


Simple answer from a quick web search http://www.longtailvideo.com/support/forums/jw-player/setup-issues-and-embedding/4212/replay-gain-in-videos

:mrgreen:
Everyone is entitled to be stupid, Image but some abuse the privilege!

Due to the confusion from too many genres of music, we have decided to put both country music and rap music into the genre of Crap music.
User avatar
BKKKPewsey
 
Posts: 2080
Joined: Mon May 23, 2011 12:16 pm
Location: United Kingdom

Re: Volume Normalization

Postby piethein » Wed Jan 25, 2012 12:08 pm

Would be great if the option to use ReplayGain tags could be implemented in the web&mobile players.
piethein
 
Posts: 35
Joined: Fri Dec 03, 2010 5:58 pm

Re: Volume Normalization

Postby Citlali » Wed Jan 25, 2012 7:03 pm

I go from flac to ogg and can only get replaygain applied by actually decoding the flac with the replaygain values applied. This isn't a lossless process, but since I'm encoding to a lossy format anyways I'm not too concerned about it. Here are my settings:

Step1 - flac -dc --totally-silent --apply-replaygain-which-is-not-lossless %s
Step2 - oggenc2 -Q -q2 -
Citlali
 
Posts: 12
Joined: Tue Aug 09, 2011 5:27 pm

Re: Volume Normalization

Postby piethein » Wed Jan 25, 2012 10:59 pm

That is a great workaround, but as I use mp3, flac, and m4a (apple lossless and aac) files it is not so easy to use replaygain in that fashion, also it loads the server more than an using the already available values in the tags of the files.
piethein
 
Posts: 35
Joined: Fri Dec 03, 2010 5:58 pm

Re: Volume Normalization

Postby jochranek » Wed Mar 21, 2012 9:04 pm

Hello,

I've been streaming my 16 bit Flac files with replaygain by using the transcoding found in this thread:

convert from:flac
convert to:mp3
Step 1:flac -d -c --apply-replaygain-which-is-not-lossless=0tLa1 %s -
Step 2:lame -b %b - -

Recently, I've started putting LPs on my computer and making them 24 bit Flac files. When I try to stream these files only 5 seconds or so of the song plays. When I reset the transcoding lines to the default of:

ffmpeg -i %s -ab %bk -v 0 -f mp3 -

the 24 bit FLACs play fine, just no replaygain. Any help getting the transcoding right for 24 bit files would be great.

Thanks,
Jason
jochranek
 
Posts: 4
Joined: Tue Apr 12, 2011 1:05 am

Re: Volume Normalization

Postby Nemo157 » Mon Oct 08, 2012 2:57 am

Since this is the first result when searching for "replaygain subsonic" I thought I'd post the solution I eventually cobbled together to apply replaygain and transcode to mp3 at the same time. This should work for any filetype that exiftool can read, the regex for finding the album gain may need to be adjusted though. It may also retain the replaygain tags in the output file, so if the player you're using understands them they will get doubled up, there's no real reason to use this in that case though.

Just install exiftool, save the following script as /var/subsonic/transcode/apply_replaygain.sh (chmod a+x) and use a transcoder with step 1: apply_replaygain.sh %s %b

Code: Select all
#!/usr/bin/env sh

volume=`exiftool -a -All -s "$1" | sed -n '/[rR]eplaygain_\?[aA]lbum_\?[gG]ain/p' | sed -n 's/.*\([-+][0-9]\+\.[0-9]\+\).*/\1/p'`
echo "ReplayGain Album Gain = ${volume}dB" >&2
ffmpeg -i "${1}" -ab "${2}k" -v warning -f mp3 -filter "volume=${volume}dB" -
User avatar
Nemo157
 
Posts: 6
Joined: Tue May 08, 2012 4:01 am
Location: New Zealand

Re: Volume Normalization

Postby ninjapuffin » Tue Oct 30, 2012 3:27 pm

Adding the ability to apply replay gain data already stored with the music would be great.
ninjapuffin
 
Posts: 9
Joined: Thu Oct 25, 2012 4:45 am

Re: Volume Normalization

Postby tomballarino » Fri Nov 29, 2013 10:55 am

I have implementes a rather quick'n'dirty approach to this:
my only transcoding is from every audio format (even mp3) to mp3. So mp3-files get de- and encoded. As step 2 in the transcoding I added one command: "mp3gain", which is a script I wrote:
-------------------
#!/bin/bash
f=`mktemp`
cat > $f
mp3gain -r -T -k $f >> /tmp/mp3gain.log
cat $f
rm $f
-----------
really messy, no error checking etc...

So every file I play gets converted to mp3, then the mp3gain command (which should be available on your system, on debian: apt-get install mp3gain) calculates the replaygain value and applies it by adjusting the overall gain of the mp3-file. So when playing this file, the player does not need to know how to interpret the ReplayGain tags.

I chose this way, cause a lot of files in my collection have ReplayGain tags, some have not, some are flac, some are mp3,... so I have to recalculate every time I play a file....which takes a lot of CPU power, so don't try this on a Rasperry!

One major drawback: the file has to be completely encoded on the server before streaming starts, so when playing through the web player, there's a few second delay after you press start. As I mostly use subsonic with the Android which caches files before playing, it doesn' bother me.

Tom
tomballarino
 
Posts: 1
Joined: Fri Nov 29, 2013 10:46 am

Re: Volume Normalization

Postby FredWallace18 » Tue Dec 24, 2013 7:47 pm

Nemo157 wrote:Just install exiftool, save the following script as /var/subsonic/transcode/apply_replaygain.sh (chmod a+x) and use a transcoder with step 1: apply_replaygain.sh %s %b

Code: Select all
#!/usr/bin/env sh

volume=`exiftool -a -All -s "$1" | sed -n '/[rR]eplaygain_\?[aA]lbum_\?[gG]ain/p' | sed -n 's/.*\([-+][0-9]\+\.[0-9]\+\).*/\1/p'`
echo "ReplayGain Album Gain = ${volume}dB" >&2
ffmpeg -i "${1}" -ab "${2}k" -v warning -f mp3 -filter "volume=${volume}dB" -


This does not seem to be working for me. It is playing the tracks at the same volume as before. My files are all tagged with the replay gain tag, but it doesn't seem to apply it. Thanks for your help--I'm getting closer!
FredWallace18
 
Posts: 8
Joined: Tue Dec 24, 2013 7:42 pm

Re: Volume Normalization

Postby wolfdown » Thu Jan 16, 2014 10:17 am

The sed commands after exif are not matching correctly. This is a less complicated command that works:

Code: Select all
# find 'replaygainalbumgain' tag, and print its value (3rd string on line)
volume=`exiftool -a -All -s "$1" | awk 'BEGIN{IGNORECASE=1} /replaygainalbumgain/ { print $3 }'`
wolfdown
 
Posts: 10
Joined: Sun Jan 05, 2014 3:25 am

Re: Volume Normalization

Postby FredWallace18 » Sat Jan 25, 2014 11:00 pm

Alright, after way too much time and experimentation, I've arrived at a solution. My biggest problems were 1)I am running Subsonic under Windows so people's clever Linux scripts weren't working; and 2)mp3s don't have a standard way of expressing replay gain, so it took a bit of time to figure out how to pull the info from my specific files. Here's everything you need to do to get what I have working:

1)Use Winamp to tag all your mp3s with replay gain metadata. This is completely reversible and doesn't damage the quality of the tracks.
2)Install awk for Windows. It's not that hard (just download the binaries and put awk.exe in the Windows directory). http://gnuwin32.sourceforge.net/packages/gawk.htm
3)Install exiftool for Windows (same). http://www.sno.phy.queensu.ca/~phil/exiftool/
4)Write the following script and name it gain.bat
Code: Select all
@echo off
cd c:\subsonic\transcode
exiftool -a -All -s %1 | awk "/(replaygain_track_gain)/ {print \"set vol=\" $4}" >tmp_.bat
call tmp_.bat
del tmp_.bat >NUL
ffmpeg -i %1 -ab %2k -v 0 -f mp3 -af volume=%vol%dB -

This runs exiftool to pull all the metadata from your mp3, then hands that off to awk, which searches for the track gain (this could all be made to search for album gain). Note that Winamp stores replay gain in "UserDefinedText" fields with names like replaygain_album_gain. That means awk has an extra column to parse, hence pulling $4. Unfortunately, I couldn't find a good way to simply assign this to a variable, so it makes a temporary batch file that makes the variable then gets deleted. Finally, ffmpeg runs, encoding the file.
5)Download the newest ffmpeg.exe and put it in your C:\subsonic\transcode. I kept the old one and just renamed it ffmpeg2.exe. ffmpeg that comes with Subsonic is old and doesn't support the -af volume switch.
6)Create a new transcoder in the Subsonic settings. Name: mp3 gain; converts from: mp3; converts to: mp3; step 1: gain.bat %s %b
7)Make sure that no other transcoders are trying to convert from mp3 or it might use them instead (I think it checks them in order and uses the first that will work for the application).

Thank you for your help, everyone in this thread. I wouldn't have gotten far without the knowledge that it's possible and the code to start from.

Anyone need further help? Ask. Anyone have a better way to write my script? Tell me! (It's really derpy, I know)
FredWallace18
 
Posts: 8
Joined: Tue Dec 24, 2013 7:42 pm

Re: Volume Normalization

Postby FredWallace18 » Mon Jan 27, 2014 6:23 am

A couple more thoughts: The replay gain tag is left in the file even after I apply it during transcoding. That means if I were to play if in a player that already supports replay gain, it would be found double. I'll try to find a way to remove the tag or set it to zero at transcoding.

The other issue is files without the tag will break the script (and Subsonic?). That will be am easy fix: try to get the value. Check if it's set. If it is, fine; if not, set it to zero or just run a transcoding that doesn't use that command.
FredWallace18
 
Posts: 8
Joined: Tue Dec 24, 2013 7:42 pm

Re: Volume Normalization

Postby grant420 » Mon Aug 04, 2014 6:24 pm

This is great, thanks a ton for doing all of the work to get this going! I will give it a try on my Windows 7 subsonic server and post my results later on.

Grant
grant420
 
Posts: 49
Joined: Fri Apr 08, 2011 8:07 pm

PreviousNext

Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 6 guests