Closed mjhalwa closed 1 year ago
Thanks for this detailed description. I have to give it some thought … but wouldn't automatically setting measured_LRA
to at least be 1 be simpler? Then users wouldn't have to specify extra flags. (I feel like we have a lot of flags already and they're getting quite confusing, even for me.)
Then again I do see your point. Would you like to file a PR for your new flag? I think if it's backwards compatible it's a good solution.
I can give it a try - probably additional rounding up to 1 is a good solution to allow both flags to work for a broad range of input_LRA
s.
Just one question: I am wondering if there is a reason for ffmpeg_normalize currently only supporting linear normalization with unchanged LRA in the second run? I mean, is it sufficient to set LRA=7
in the first run or is it preferrable to set LRA=7
in the 2nd run or is LRA=7
actually not required to fullfill EBU R128
I would probably just add a check before setting the opts
here: https://github.com/slhck/ffmpeg-normalize/blob/7cd65d510dc2f2176358157980493c1735c62180/ffmpeg_normalize/_streams.py#L435 and output a warning if the loudness_range_target
is below 1 (or above 50), saying that it was increased to 1 (or decreased to 50). That ensures we always produce a working command line. But I welcome a PR, since you also have the files to test with!
I believe that if you set LRA, you need to set it for the second run, since that will actually do the processing. The first run is only there to identify the properties of the file.
I forked your project's master branch at 7cd65d5 and tried and setup (for me I use a virtual environment with pipenv
):
pipenv install
pipenv install --dev -r .\requirements.dev.txt
I just wanted to make sure, I am able to run everything and don't miss anything. So I tried to execute help with with pipenv run python -m ffmpeg_normalize -h
- that worked. But runnint pytest
with
pipenv run pytest .\test\test.py
seems to fail in 5 out of 25 tests.
➜ pipenv run pytest .\test\test.py
================================================= test session starts =================================================
platform win32 -- Python 3.11.0, pytest-7.3.1, pluggy-1.0.0
rootdir: C:\Daten\Git\ffmpeg-normalize
collected 25 items
test\test.py ......FFF.............FF. [100%]
====================================================== FAILURES =======================================================
____________________________________________ TestFFmpegNormalize.test_peak ____________________________________________
# ...
=============================================== short test summary info ===============================================
FAILED test/test.py::TestFFmpegNormalize::test_peak - AssertionError: assert False
FAILED test/test.py::TestFFmpegNormalize::test_rms - AssertionError: assert False
FAILED test/test.py::TestFFmpegNormalize::test_ebu - AssertionError: assert False
FAILED test/test.py::TestFFmpegNormalize::test_pre_filters - AssertionError: assert False
FAILED test/test.py::TestFFmpegNormalize::test_post_filters - AssertionError: assert False
============================================ 5 failed, 20 passed in 22.67s ============================================
Do I miss something or is this currently fine?
Could you please try to create a PR against this repository? I have automated tests that should ensure everything is fine.
If you like, I could also create a PR to silently set LRA
to 1, if it is lower than 1 for --keep-loudness-range-target
, in order to fix this flag too. Or would you like me to add it to the same PR?
Fixed by c49480c3eeb64eeb02d021b3e9e574499f4cdc0f.
I added a constraint for the input LRA between 1 and 7 in 3187a02d6e5200949da36a8164277de6a6929b9a
Is your feature request related to a problem? Please describe.
Yes, I am currently using
ffmpeg-normalize 1.26.4
inPython 3.10.9
withwhere 2nd runs with
ffmpeg
execute withlra={input_lra}
which produces alinear
normalized audio for anyinput_lra >= 1
. If I try to convert a song withinput_lra < 1
(e.g.0.7
in audio from https://www.youtube.com/watch?v=HTYOa2_1aH4) I get the following error:I am able to resolve this issue by using
loudness_range_target=7.0,
instead ofkeep_loudness_range_target=True
for anyinput_lra <= 7.0
, but then get the following warning forinput_lra > 7
(e.g.16.10
in audio from https://www.youtube.com/watch?v=GibiNy4d4gc):which does perform
dynamic
normalization instead oflinear
normalization.Describe the solution you'd like
In order to solve this and ensure backwards compatibility I'd suggest to a add a flag
--keep-lra-above-loudness-range-target
(constructor parameter:keep_lra_above_loudness_range_target=True
). In combination withloudness_range_target=7.0
. This should ensureLRA=7
forinput_lra <= 7
andLRA=input_lra
forinput_lra > 7
and allows to convert any song with the same parameter-set independent ofinput_lra
Describe alternatives you've considered
An alternative solution would be to set
input_lra < 1
toLRA=1
in order to fit into the range of[1 - 50]
with something like--force-linear-normalization
Without any change in
ffmpeg_normalize
I would need to measureinput_lra
in order to know what parameters to set, but then I can basically useffmpeg
directly without usingffmpeg_normalize
at all.Additional context
I am new to the topic of audio normalization, followed some tutorials and weblinks, played around with ffmpeg in order to achieve
linear
normalization, as I did not like howdynamic
normalization changed the audio. I read thattarget_LRA
should be7.0
(EBU R128) and therefore used7.0
when possible (so ifinput_lra < 7
) and usedLRA=input_lra
forLRA > 7
. Using--keep-loudness-range-target
inffmpeg_normalize
seems to override--loudness-range-target = 7.0
and therefore only useLRA=7.0
, if theinput_lra
is already7.0
. So I hope--keep-lra-above-loudness-range-target
might be an improvement by respecting--loudness-range-target = 7.0
as long as possible.