HaveAGitGat / Tdarr_Plugins

Tdarr Plugins
GNU General Public License v3.0
140 stars 158 forks source link

Independent Channel Normalization #687

Open Funtime60 opened 3 months ago

Funtime60 commented 3 months ago

The default audio normalization plugin is the easiest, possibly only, way of normalizing audio with 2 passes. It would be nice if it could be used on each channel independently to fix audio balance issues.

Currently it seems to use: ffmpeg -i args.inputFileObj._id -af "loudnorm=I=".concat(loudNorm_i, ":LRA=").concat(lra, ":TP=").concat(tp, ":print_format=json") -f null NUL -map 0 -c copy and: ffmpeg -i args.inputFileObj._id -map 0 -c copy -c:a aac -b:a 192k -af "loudnorm=print_format=summary:linear=true:I=".concat(loudNorm_i, ":LRA=").concat(lra, ":TP=").concat(tp, ":") + "measured_i=".concat(loudNormValues.input_i, ":") + "measured_lra=".concat(loudNormValues.input_lra, ":") + "measured_tp=".concat(loudNormValues.input_tp, ":") + "measured_thresh=".concat(loudNormValues.input_thresh, ":offset=").concat(loudNormValues.target_offset, " ") outputFilePath

By replacing the first one with: ffmpeg -filter_complex 'channelsplit=channel_layout=stereo[l][r];[l]loudnorm=print_format=json,aformat=sample_rates=48000:channel_layouts=mono[l2];[r]loudnorm=print_format=json,aformat=sample_rates=48000:channel_layouts=mono[r2];[l2][r2]join[out]' -map "[out]" -f null - and adjusting the second one to use the extra info

It can independently normalize each channel in a stereo audio file and this could be expanded to accept any channel count.

I'm pretty sure I could get the JS and the FFmpeg to work myself, I just don't know how to give it to github. Do I fork and do it there...?

Funtime60 commented 3 months ago

Nevermind me doing this myself, I have no idea how to test any of the changes I'd need to make.