help understanding batch mode and transcoding strategy
Describe what you are attempting to do
normalize many individual music files and treat them as though they were an album in order to apply an even/linear gain across all files
obviously i can use the --batch option, but i prefer to process the files 1-by-1 (i'm doing other processing with them), so my question is, will using --batch and single-file processing provide the desired result, or does ffmpeg need to 'see' all the files at once?
i'm starting with flac's that already have ReplayGain metadata, but i need stream-normalized mp3's for a particular device that doesn't read ReplayGain tags
currently i'm using...
ffmpeg -hide_banner -i "${sFile}" -af 'silenceremove=start_periods=1:start_threshold=-89dB:stop_threshold=-89dB' './input/silenceremove.wav'
ffmpeg-normalize './input/silenceremove.wav' --progress --preset 'music' --output='./input/normalize.wav'
ffmpeg -hide_banner -i './input/normalize.wav' -codec:a 'libmp3lame' -ar 44100 -q:a 0 -map_metadata 0 -id3v2_version 3 "${sFile/%flac/mp3}"
ffmpeg-normalize 1.36.0 ffmpeg 7.1.1 Manjaro Linux
You cannot achieve album-style normalization by processing files one-by-one. The --batch mode requires ffmpeg-normalize to "see" all files at once and compute the required offsets based on the average of all files.
But if I understand correctly, you have ReplayGain tags, and you want the output to be normalized according to that, with your additional silence removal filter.
Wouldn't this do the job, all in one go?
ffmpeg -hide_banner -i "$input" -af "silenceremove=...,volume=replaygain=album" -codec:a libmp3lame -ar 44100 -q:a 0 "${input%.flac}.mp3"
This uses ffmpeg's built-in replaygain=album volume filter option, which reads the ReplayGain album tags and applies them based on the album context, but in a per-track process.
oh, nice!
i see when i wrote the gain tags in the original flac's with rsgain, i wrote RG 'track' tags (so volume=replaygain=track"), but when i compare the original flac to the mp3 with Audacious (RG enabled, 'track' mode) the mp3 is much quieter for reasons i don't understand
EDIT - i think i answered my own question - ffmpeg is normalizing the audio stream and Audaciious is applying the RG info on top of that :)
Glad you figured it out! So I suppose the -map_metadata 0 is copying the RG tags to the MP3 which causes Audacious to apply the gain twice?
One issue in your command is using -af twice… it doesn't chain the filters! The second one actually overrides the first, so your silenceremove isn't being applied. You need to combine them with a comma:
ffmpeg -hide_banner -i "${sFile}" \
-af 'silenceremove=start_periods=1:start_threshold=-89dB:stop_threshold=-89dB,volume=replaygain=track' \
-codec:a libmp3lame -ar 44100 -q:a 0 \
-map_metadata 0 -id3v2_version 3 \
"${sFile/%flac/mp3}"
I think (have not verified though!) that if you set:
-metadata REPLAYGAIN_TRACK_GAIN= -metadata REPLAYGAIN_TRACK_PEAK=
you can basically erase the ReplayGain data and still copy over the other metadata.
yeah, i think that's what was happening - ffmpeg-normailize was applying gain to the stream + the RG metadata was being read by Audacity
i was also wrong about my device not reading RG tags (device being an entertainment console in a vehicle, hence why i needed mp3's - it doesn't do flac), so there again RG was applied twice!
so it's all a lot simpler now - 1 util instead of 3...
mapfile -d '' aFiles < <(find -- "${sInDir}/" -type 'f' -iname "*.${sExt}" -print0)
for sFile in "${aFiles[@]}" ; do
printf '%s\n' "Processing ${sFile} ..."
s="$(basename "${sFile/%flac/mp3}")"
ffmpeg -hide_banner -loglevel 'warning' -i "${sFile}" -codec:a 'libmp3lame' -ar 44100 -q:a 0 -map_metadata 0 -id3v2_version 3 "${sOutDir}/${s}"
done
and thanks for the filter tip (the comma thing) ... just for kix, does the same hold true when using -af + -ar?
-af 'volume=replaygain=track' -codec:a 'libmp3lame' -ar 44100 -q:a 0
according to ffmpeg -i, the files have gain tags and it's spitting out mp3's, so i'm guessing the comma isn't needed here?
Not sure if I got your question right, but -ar and -af do not merge/overwrite themselves. -ar is a shortcut for specifying the aresample filter.
according to ffmpeg -i, the files have gain tags and it's spitting out mp3's, so i'm guessing the comma isn't needed here?
Not sure which comma you are referring to? My comment was related to specifying -af twice. Your command looks fine now although it's not using the silenceremove filter anymore.
you answered my question, even if you don't know it :)
ffmpeg is hard
have a good one!
Thanks, glad you got everything solved!
thank you - you prompted me to make changes in another script where i can dump some dependencies in favor of ffmpeg - if your interested, have a look at Muzik Faktry