sandreas / m4b-tool

m4b-tool is a command line utility to merge, split and chapterize audiobook files such as mp3, ogg, flac, m4a or m4b
MIT License
1.15k stars 76 forks source link

Add option for dynamic FFmpeg sound volume normalization for the merge command #226

Closed devnoname120 closed 1 year ago

devnoname120 commented 1 year ago

Particularly useful for voices as they can get farther and closer to the mic.

Note: the first loudnorm pass should be run through the collection of all the inputs to make sure that the dynamic normalization is consistent across the whole merged file.

For example for converting MP3 files to M4B:

ffmpeg -i part1.mp3 -i part2.mp3 -i part3.mp3 -filter_complex 'concat=n=3:v=0:a=1[a]; [a]loudnorm=I=-16:TP=-1.5:LRA=11:print_format=json' -f null -

output:

{
    "input_i" : "-22.99",
    "input_tp" : "-6.99",
    "input_lra" : "7.00",
    "input_thresh" : "-34.56",
    "output_i" : "-16.73",
    "output_tp" : "-1.50",
    "output_lra" : "6.80",
    "output_thresh" : "-28.29",
    "normalization_type" : "dynamic",
    "target_offset" : "0.73"
}
ffmpeg -i part1.mp3 -ab 196k -ar 44100 -ac 2 -af loudnorm=I=-16:TP=-1.5:LRA=11:measured_I=-22.99:measured_TP=-6.99:measured_LRA=7:measured_thresh=-34.56:offset=0.73:linear=true:print_format=summary -f mp4 part1.m4b

ffmpeg -i part2.mp3 -ab 196k -ar 44100 -ac 2 -af loudnorm=I=-16:TP=-1.5:LRA=11:measured_I=-22.99:measured_TP=-6.99:measured_LRA=7:measured_thresh=-34.56:offset=0.73:linear=true:print_format=summary -f mp4 part2.m4b

ffmpeg -i part3.mp3 -ab 196k -ar 44100 -ac 2 -af loudnorm=I=-16:TP=-1.5:LRA=11:measured_I=-22.99:measured_TP=-6.99:measured_LRA=7:measured_thresh=-34.56:offset=0.73:linear=true:print_format=summary -f mp4 part3.m4b

m4b-tool merge -vvv --debug --no-conversion --include-extensions=m4b --output-file="merged.m4b" .
devnoname120 commented 1 year ago

Ah it looks like there is already an issue about this: https://github.com/sandreas/m4b-tool/issues/121

sandreas commented 1 year ago

Ah it looks like there is already an issue about this: https://github.com/sandreas/m4b-tool/issues/121

Can I close this issue in favor of #121? I think it already contains a detailed description of what would be the best approach to integrate the loudness normalisation feature.

Although I doubt that I will have the time to integrate it soon. Maybe you wanna give it a shot?

devnoname120 commented 1 year ago

Can be closed I agree 👍 I'll copy my comment there