ffmpeg-normalize 1.29.2__py2.py3-none-any.whl → 1.31.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ffmpeg_normalize/__main__.py +31 -3
- ffmpeg_normalize/_cmd_utils.py +3 -3
- ffmpeg_normalize/_ffmpeg_normalize.py +11 -2
- ffmpeg_normalize/_media_file.py +49 -20
- ffmpeg_normalize/_streams.py +79 -92
- ffmpeg_normalize/_version.py +1 -1
- {ffmpeg_normalize-1.29.2.dist-info → ffmpeg_normalize-1.31.0.dist-info}/METADATA +121 -11
- ffmpeg_normalize-1.31.0.dist-info/RECORD +16 -0
- ffmpeg_normalize-1.29.2.dist-info/RECORD +0 -16
- {ffmpeg_normalize-1.29.2.dist-info → ffmpeg_normalize-1.31.0.dist-info}/LICENSE +0 -0
- {ffmpeg_normalize-1.29.2.dist-info → ffmpeg_normalize-1.31.0.dist-info}/WHEEL +0 -0
- {ffmpeg_normalize-1.29.2.dist-info → ffmpeg_normalize-1.31.0.dist-info}/entry_points.txt +0 -0
- {ffmpeg_normalize-1.29.2.dist-info → ffmpeg_normalize-1.31.0.dist-info}/top_level.txt +0 -0
ffmpeg_normalize/__main__.py
CHANGED
|
@@ -201,9 +201,7 @@ def create_parser() -> argparse.ArgumentParser:
|
|
|
201
201
|
help=textwrap.dedent(
|
|
202
202
|
"""\
|
|
203
203
|
Keep input loudness range above loudness range target.
|
|
204
|
-
|
|
205
|
-
- keep input loudness range target above `LOUDNESS_RANGE_TARGET`.
|
|
206
|
-
as alternative to `--keep-loudness-range-target` to allow for linear normalization.
|
|
204
|
+
Can be used as an alternative to `--keep-loudness-range-target` to allow for linear normalization.
|
|
207
205
|
"""
|
|
208
206
|
),
|
|
209
207
|
)
|
|
@@ -235,6 +233,34 @@ def create_parser() -> argparse.ArgumentParser:
|
|
|
235
233
|
default=0.0,
|
|
236
234
|
)
|
|
237
235
|
|
|
236
|
+
group_ebu.add_argument(
|
|
237
|
+
"--lower-only",
|
|
238
|
+
action="store_true",
|
|
239
|
+
help=textwrap.dedent(
|
|
240
|
+
"""\
|
|
241
|
+
Whether the audio should not increase in loudness.
|
|
242
|
+
|
|
243
|
+
If the measured loudness from the first pass is lower than the target
|
|
244
|
+
loudness then normalization pass will be skipped for the measured audio
|
|
245
|
+
source.
|
|
246
|
+
"""
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
group_ebu.add_argument(
|
|
251
|
+
"--auto-lower-loudness-target",
|
|
252
|
+
action="store_true",
|
|
253
|
+
help=textwrap.dedent(
|
|
254
|
+
"""\
|
|
255
|
+
Automatically lower EBU Integrated Loudness Target to prevent falling
|
|
256
|
+
back to dynamic filtering.
|
|
257
|
+
|
|
258
|
+
Makes sure target loudness is lower than measured loudness minus peak
|
|
259
|
+
loudness (input_i - input_tp) by a small amount (0.1 LUFS).
|
|
260
|
+
"""
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
|
|
238
264
|
group_ebu.add_argument(
|
|
239
265
|
"--dual-mono",
|
|
240
266
|
action="store_true",
|
|
@@ -514,6 +540,8 @@ def main() -> None:
|
|
|
514
540
|
keep_lra_above_loudness_range_target=cli_args.keep_lra_above_loudness_range_target,
|
|
515
541
|
true_peak=cli_args.true_peak,
|
|
516
542
|
offset=cli_args.offset,
|
|
543
|
+
lower_only=cli_args.lower_only,
|
|
544
|
+
auto_lower_loudness_target=cli_args.auto_lower_loudness_target,
|
|
517
545
|
dual_mono=cli_args.dual_mono,
|
|
518
546
|
dynamic=cli_args.dynamic,
|
|
519
547
|
audio_codec=cli_args.audio_codec,
|
ffmpeg_normalize/_cmd_utils.py
CHANGED
|
@@ -7,7 +7,7 @@ import shlex
|
|
|
7
7
|
import subprocess
|
|
8
8
|
from platform import system
|
|
9
9
|
from shutil import which
|
|
10
|
-
from typing import Iterator
|
|
10
|
+
from typing import Iterator, Any
|
|
11
11
|
|
|
12
12
|
from ffmpeg_progress_yield import FfmpegProgress
|
|
13
13
|
|
|
@@ -128,12 +128,12 @@ class CommandRunner:
|
|
|
128
128
|
return self.output
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
def dict_to_filter_opts(opts: dict[str,
|
|
131
|
+
def dict_to_filter_opts(opts: dict[str, Any]) -> str:
|
|
132
132
|
"""
|
|
133
133
|
Convert a dictionary to a ffmpeg filter option string
|
|
134
134
|
|
|
135
135
|
Args:
|
|
136
|
-
opts (dict[str,
|
|
136
|
+
opts (dict[str, Any]): Dictionary of options
|
|
137
137
|
|
|
138
138
|
Returns:
|
|
139
139
|
str: Filter option string
|
|
@@ -3,6 +3,8 @@ from __future__ import annotations
|
|
|
3
3
|
import json
|
|
4
4
|
import logging
|
|
5
5
|
import os
|
|
6
|
+
import sys
|
|
7
|
+
from itertools import chain
|
|
6
8
|
from typing import TYPE_CHECKING, Literal
|
|
7
9
|
|
|
8
10
|
from tqdm import tqdm
|
|
@@ -58,6 +60,8 @@ class FFmpegNormalize:
|
|
|
58
60
|
keep_lra_above_loudness_range_target (bool, optional): Keep input loudness range above loudness range target. Defaults to False.
|
|
59
61
|
true_peak (float, optional): True peak. Defaults to -2.0.
|
|
60
62
|
offset (float, optional): Offset. Defaults to 0.0.
|
|
63
|
+
lower_only (bool, optional): Whether the audio should not increase in loudness. Defaults to False.
|
|
64
|
+
auto_lower_loudness_target (bool, optional): Automatically lower EBU Integrated Loudness Target.
|
|
61
65
|
dual_mono (bool, optional): Dual mono. Defaults to False.
|
|
62
66
|
dynamic (bool, optional): Dynamic. Defaults to False.
|
|
63
67
|
audio_codec (str, optional): Audio codec. Defaults to "pcm_s16le".
|
|
@@ -94,6 +98,8 @@ class FFmpegNormalize:
|
|
|
94
98
|
keep_lra_above_loudness_range_target: bool = False,
|
|
95
99
|
true_peak: float = -2.0,
|
|
96
100
|
offset: float = 0.0,
|
|
101
|
+
lower_only: bool = False,
|
|
102
|
+
auto_lower_loudness_target: bool = False,
|
|
97
103
|
dual_mono: bool = False,
|
|
98
104
|
dynamic: bool = False,
|
|
99
105
|
audio_codec: str = "pcm_s16le",
|
|
@@ -164,6 +170,8 @@ class FFmpegNormalize:
|
|
|
164
170
|
|
|
165
171
|
self.true_peak = check_range(true_peak, -9, 0, name="true_peak")
|
|
166
172
|
self.offset = check_range(offset, -99, 99, name="offset")
|
|
173
|
+
self.lower_only = lower_only
|
|
174
|
+
self.auto_lower_loudness_target = auto_lower_loudness_target
|
|
167
175
|
|
|
168
176
|
# Ensure library user is passing correct types
|
|
169
177
|
assert isinstance(dual_mono, bool), "dual_mono must be bool"
|
|
@@ -254,5 +262,6 @@ class FFmpegNormalize:
|
|
|
254
262
|
|
|
255
263
|
_logger.info(f"Normalized file written to {media_file.output_file}")
|
|
256
264
|
|
|
257
|
-
if self.print_stats
|
|
258
|
-
|
|
265
|
+
if self.print_stats:
|
|
266
|
+
json.dump(list(chain.from_iterable(media_file.get_stats() for media_file in self.media_files)), sys.stdout, indent=4)
|
|
267
|
+
print()
|
ffmpeg_normalize/_media_file.py
CHANGED
|
@@ -6,13 +6,18 @@ import re
|
|
|
6
6
|
import shlex
|
|
7
7
|
from shutil import move, rmtree
|
|
8
8
|
from tempfile import mkdtemp
|
|
9
|
-
from typing import TYPE_CHECKING, Iterator, Literal, TypedDict
|
|
9
|
+
from typing import TYPE_CHECKING, Iterable, Iterator, Literal, TypedDict
|
|
10
10
|
|
|
11
11
|
from tqdm import tqdm
|
|
12
12
|
|
|
13
13
|
from ._cmd_utils import DUR_REGEX, NUL, CommandRunner
|
|
14
14
|
from ._errors import FFmpegNormalizeError
|
|
15
|
-
from ._streams import
|
|
15
|
+
from ._streams import (
|
|
16
|
+
AudioStream,
|
|
17
|
+
LoudnessStatisticsWithMetadata,
|
|
18
|
+
SubtitleStream,
|
|
19
|
+
VideoStream,
|
|
20
|
+
)
|
|
16
21
|
|
|
17
22
|
if TYPE_CHECKING:
|
|
18
23
|
from ffmpeg_normalize import FFmpegNormalize
|
|
@@ -240,11 +245,6 @@ class MediaFile:
|
|
|
240
245
|
for _ in fun():
|
|
241
246
|
pass
|
|
242
247
|
|
|
243
|
-
# set initial stats (for dry-runs, this is the only thing we need to do)
|
|
244
|
-
self.ffmpeg_normalize.stats = [
|
|
245
|
-
audio_stream.get_stats() for audio_stream in self.streams["audio"].values()
|
|
246
|
-
]
|
|
247
|
-
|
|
248
248
|
def _get_audio_filter_cmd(self) -> tuple[str, list[str]]:
|
|
249
249
|
"""
|
|
250
250
|
Return the audio filter command and output labels needed.
|
|
@@ -256,10 +256,40 @@ class MediaFile:
|
|
|
256
256
|
output_labels = []
|
|
257
257
|
|
|
258
258
|
for audio_stream in self.streams["audio"].values():
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
skip_normalization = False
|
|
260
|
+
if self.ffmpeg_normalize.lower_only:
|
|
261
|
+
if self.ffmpeg_normalize.normalization_type == "ebu":
|
|
262
|
+
if (
|
|
263
|
+
audio_stream.loudness_statistics["ebu_pass1"] is not None
|
|
264
|
+
and audio_stream.loudness_statistics["ebu_pass1"]["input_i"]
|
|
265
|
+
< self.ffmpeg_normalize.target_level
|
|
266
|
+
):
|
|
267
|
+
skip_normalization = True
|
|
268
|
+
elif self.ffmpeg_normalize.normalization_type == "peak":
|
|
269
|
+
if (
|
|
270
|
+
audio_stream.loudness_statistics["max"] is not None
|
|
271
|
+
and audio_stream.loudness_statistics["max"]
|
|
272
|
+
< self.ffmpeg_normalize.target_level
|
|
273
|
+
):
|
|
274
|
+
skip_normalization = True
|
|
275
|
+
elif self.ffmpeg_normalize.normalization_type == "rms":
|
|
276
|
+
if (
|
|
277
|
+
audio_stream.loudness_statistics["mean"] is not None
|
|
278
|
+
and audio_stream.loudness_statistics["mean"]
|
|
279
|
+
< self.ffmpeg_normalize.target_level
|
|
280
|
+
):
|
|
281
|
+
skip_normalization = True
|
|
282
|
+
|
|
283
|
+
if skip_normalization:
|
|
284
|
+
_logger.warning(
|
|
285
|
+
f"Stream {audio_stream.stream_id} had measured input loudness lower than target, skipping normalization."
|
|
286
|
+
)
|
|
287
|
+
normalization_filter = "acopy"
|
|
261
288
|
else:
|
|
262
|
-
|
|
289
|
+
if self.ffmpeg_normalize.normalization_type == "ebu":
|
|
290
|
+
normalization_filter = audio_stream.get_second_pass_opts_ebu()
|
|
291
|
+
else:
|
|
292
|
+
normalization_filter = audio_stream.get_second_pass_opts_peakrms()
|
|
263
293
|
|
|
264
294
|
input_label = f"[0:{audio_stream.stream_id}]"
|
|
265
295
|
output_label = f"[norm{audio_stream.stream_id}]"
|
|
@@ -421,16 +451,10 @@ class MediaFile:
|
|
|
421
451
|
# in the second pass, we do not normalize stream-by-stream, so we set the stats based on the
|
|
422
452
|
# overall output (which includes multiple loudnorm stats)
|
|
423
453
|
if self.ffmpeg_normalize.normalization_type == "ebu":
|
|
424
|
-
all_stats = AudioStream.prune_and_parse_loudnorm_output(
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
audio_stream.set_second_pass_stats(all_stats[idx])
|
|
429
|
-
|
|
430
|
-
# collect all stats for the final report, again (overwrite the input)
|
|
431
|
-
self.ffmpeg_normalize.stats = [
|
|
432
|
-
audio_stream.get_stats() for audio_stream in self.streams["audio"].values()
|
|
433
|
-
]
|
|
454
|
+
all_stats = AudioStream.prune_and_parse_loudnorm_output(output)
|
|
455
|
+
for stream_id, audio_stream in self.streams["audio"].items():
|
|
456
|
+
if stream_id in all_stats:
|
|
457
|
+
audio_stream.set_second_pass_stats(all_stats[stream_id])
|
|
434
458
|
|
|
435
459
|
# warn if self.media_file.ffmpeg_normalize.dynamic == False and any of the second pass stats contain "normalization_type" == "dynamic"
|
|
436
460
|
if self.ffmpeg_normalize.dynamic is False:
|
|
@@ -446,3 +470,8 @@ class MediaFile:
|
|
|
446
470
|
)
|
|
447
471
|
|
|
448
472
|
_logger.debug("Normalization finished")
|
|
473
|
+
|
|
474
|
+
def get_stats(self) -> Iterable[LoudnessStatisticsWithMetadata]:
|
|
475
|
+
return (
|
|
476
|
+
audio_stream.get_stats() for audio_stream in self.streams["audio"].values()
|
|
477
|
+
)
|
ffmpeg_normalize/_streams.py
CHANGED
|
@@ -15,6 +15,7 @@ if TYPE_CHECKING:
|
|
|
15
15
|
|
|
16
16
|
_logger = logging.getLogger(__name__)
|
|
17
17
|
|
|
18
|
+
_loudnorm_pattern = re.compile(r"\[Parsed_loudnorm_(\d+)")
|
|
18
19
|
|
|
19
20
|
class EbuLoudnessStatistics(TypedDict):
|
|
20
21
|
input_i: float
|
|
@@ -166,7 +167,7 @@ class AudioStream(MediaStream):
|
|
|
166
167
|
}
|
|
167
168
|
return stats
|
|
168
169
|
|
|
169
|
-
def set_second_pass_stats(self, stats: EbuLoudnessStatistics):
|
|
170
|
+
def set_second_pass_stats(self, stats: EbuLoudnessStatistics) -> None:
|
|
170
171
|
"""
|
|
171
172
|
Set the EBU loudness statistics for the second pass.
|
|
172
173
|
|
|
@@ -320,58 +321,36 @@ class AudioStream(MediaStream):
|
|
|
320
321
|
f"Loudnorm first pass command output: {CommandRunner.prune_ffmpeg_progress_from_output(output)}"
|
|
321
322
|
)
|
|
322
323
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
output, num_stats=1
|
|
326
|
-
)[0] # only one stream
|
|
327
|
-
)
|
|
324
|
+
# only one stream
|
|
325
|
+
self.loudness_statistics["ebu_pass1"] = next(iter(AudioStream.prune_and_parse_loudnorm_output(output).values()))
|
|
328
326
|
|
|
329
327
|
@staticmethod
|
|
330
328
|
def prune_and_parse_loudnorm_output(
|
|
331
|
-
output: str
|
|
332
|
-
) ->
|
|
329
|
+
output: str
|
|
330
|
+
) -> dict[int, EbuLoudnessStatistics]:
|
|
333
331
|
"""
|
|
334
332
|
Prune ffmpeg progress lines from output and parse the loudnorm filter output.
|
|
335
333
|
There may be multiple outputs if multiple streams were processed.
|
|
336
334
|
|
|
337
335
|
Args:
|
|
338
336
|
output (str): The output from ffmpeg.
|
|
339
|
-
num_stats (int): The number of loudnorm statistics to parse.
|
|
340
337
|
|
|
341
338
|
Returns:
|
|
342
339
|
list: The EBU loudness statistics.
|
|
343
340
|
"""
|
|
344
341
|
pruned_output = CommandRunner.prune_ffmpeg_progress_from_output(output)
|
|
345
342
|
output_lines = [line.strip() for line in pruned_output.split("\n")]
|
|
346
|
-
|
|
347
|
-
ret = []
|
|
348
|
-
idx = 0
|
|
349
|
-
while True:
|
|
350
|
-
_logger.debug(f"Parsing loudnorm stats for stream {idx}")
|
|
351
|
-
loudnorm_stats = AudioStream._parse_loudnorm_output(
|
|
352
|
-
output_lines, stream_index=idx
|
|
353
|
-
)
|
|
354
|
-
idx += 1
|
|
355
|
-
|
|
356
|
-
if loudnorm_stats is None:
|
|
357
|
-
continue
|
|
358
|
-
ret.append(loudnorm_stats)
|
|
359
|
-
|
|
360
|
-
if len(ret) >= num_stats:
|
|
361
|
-
break
|
|
362
|
-
|
|
363
|
-
return ret
|
|
343
|
+
return AudioStream._parse_loudnorm_output(output_lines)
|
|
364
344
|
|
|
365
345
|
@staticmethod
|
|
366
346
|
def _parse_loudnorm_output(
|
|
367
|
-
output_lines: list[str]
|
|
368
|
-
) ->
|
|
347
|
+
output_lines: list[str]
|
|
348
|
+
) -> dict[int, EbuLoudnessStatistics]:
|
|
369
349
|
"""
|
|
370
350
|
Parse the output of a loudnorm filter to get the EBU loudness statistics.
|
|
371
351
|
|
|
372
352
|
Args:
|
|
373
353
|
output_lines (list[str]): The output lines of the loudnorm filter.
|
|
374
|
-
stream_index (int): The stream index, optional to filter out the correct stream. If unset, the first stream is used.
|
|
375
354
|
|
|
376
355
|
Raises:
|
|
377
356
|
FFmpegNormalizeError: When the output could not be parsed.
|
|
@@ -379,64 +358,58 @@ class AudioStream(MediaStream):
|
|
|
379
358
|
Returns:
|
|
380
359
|
EbuLoudnessStatistics: The EBU loudness statistics, if found.
|
|
381
360
|
"""
|
|
361
|
+
result = dict[int, EbuLoudnessStatistics]()
|
|
362
|
+
stream_index = -1
|
|
382
363
|
loudnorm_start = 0
|
|
383
|
-
loudnorm_end = 0
|
|
384
364
|
for index, line in enumerate(output_lines):
|
|
385
|
-
if
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
loudnorm_stats[key] = float(loudnorm_stats[key])
|
|
434
|
-
|
|
435
|
-
return cast(EbuLoudnessStatistics, loudnorm_stats)
|
|
436
|
-
except Exception as e:
|
|
437
|
-
raise FFmpegNormalizeError(
|
|
438
|
-
f"Could not parse loudnorm stats; wrong JSON format in string: {e}"
|
|
439
|
-
)
|
|
365
|
+
if stream_index < 0:
|
|
366
|
+
if m := _loudnorm_pattern.match(line):
|
|
367
|
+
loudnorm_start = index + 1
|
|
368
|
+
stream_index = int(m.group(1))
|
|
369
|
+
else:
|
|
370
|
+
if line.startswith("}"):
|
|
371
|
+
loudnorm_end = index + 1
|
|
372
|
+
loudnorm_data = "\n".join(output_lines[loudnorm_start:loudnorm_end])
|
|
373
|
+
|
|
374
|
+
try:
|
|
375
|
+
loudnorm_stats = json.loads(loudnorm_data)
|
|
376
|
+
|
|
377
|
+
_logger.debug(
|
|
378
|
+
f"Loudnorm stats for stream {stream_index} parsed: {loudnorm_data}"
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
for key in [
|
|
382
|
+
"input_i",
|
|
383
|
+
"input_tp",
|
|
384
|
+
"input_lra",
|
|
385
|
+
"input_thresh",
|
|
386
|
+
"output_i",
|
|
387
|
+
"output_tp",
|
|
388
|
+
"output_lra",
|
|
389
|
+
"output_thresh",
|
|
390
|
+
"target_offset",
|
|
391
|
+
"normalization_type",
|
|
392
|
+
]:
|
|
393
|
+
if key not in loudnorm_stats:
|
|
394
|
+
continue
|
|
395
|
+
if key == "normalization_type":
|
|
396
|
+
loudnorm_stats[key] = loudnorm_stats[key].lower()
|
|
397
|
+
# handle infinite values
|
|
398
|
+
elif float(loudnorm_stats[key]) == -float("inf"):
|
|
399
|
+
loudnorm_stats[key] = -99
|
|
400
|
+
elif float(loudnorm_stats[key]) == float("inf"):
|
|
401
|
+
loudnorm_stats[key] = 0
|
|
402
|
+
else:
|
|
403
|
+
# convert to floats
|
|
404
|
+
loudnorm_stats[key] = float(loudnorm_stats[key])
|
|
405
|
+
|
|
406
|
+
result[stream_index] = cast(EbuLoudnessStatistics, loudnorm_stats)
|
|
407
|
+
stream_index = -1
|
|
408
|
+
except Exception as e:
|
|
409
|
+
raise FFmpegNormalizeError(
|
|
410
|
+
f"Could not parse loudnorm stats; wrong JSON format in string: {e}"
|
|
411
|
+
)
|
|
412
|
+
return result
|
|
440
413
|
|
|
441
414
|
def get_second_pass_opts_ebu(self) -> str:
|
|
442
415
|
"""
|
|
@@ -508,26 +481,40 @@ class AudioStream(MediaStream):
|
|
|
508
481
|
"Specify -ar/--sample-rate to override it."
|
|
509
482
|
)
|
|
510
483
|
|
|
484
|
+
target_level = self.ffmpeg_normalize.target_level
|
|
485
|
+
if self.ffmpeg_normalize.auto_lower_loudness_target:
|
|
486
|
+
safe_target = (
|
|
487
|
+
self.loudness_statistics["ebu_pass1"]["input_i"]
|
|
488
|
+
- self.loudness_statistics["ebu_pass1"]["input_tp"]
|
|
489
|
+
+ self.ffmpeg_normalize.true_peak
|
|
490
|
+
- 0.1
|
|
491
|
+
)
|
|
492
|
+
if safe_target < self.ffmpeg_normalize.target_level:
|
|
493
|
+
target_level = safe_target
|
|
494
|
+
_logger.warning(
|
|
495
|
+
f"Using loudness target {target_level} because --auto-lower-loudness-target given.",
|
|
496
|
+
)
|
|
497
|
+
|
|
511
498
|
stats = self.loudness_statistics["ebu_pass1"]
|
|
512
499
|
|
|
513
500
|
opts = {
|
|
514
|
-
"i":
|
|
501
|
+
"i": target_level,
|
|
515
502
|
"lra": self.media_file.ffmpeg_normalize.loudness_range_target,
|
|
516
503
|
"tp": self.media_file.ffmpeg_normalize.true_peak,
|
|
517
504
|
"offset": self._constrain(
|
|
518
|
-
|
|
505
|
+
stats["target_offset"], -99, 99, name="target_offset"
|
|
519
506
|
),
|
|
520
507
|
"measured_i": self._constrain(
|
|
521
|
-
|
|
508
|
+
stats["input_i"], -99, 0, name="input_i"
|
|
522
509
|
),
|
|
523
510
|
"measured_lra": self._constrain(
|
|
524
|
-
|
|
511
|
+
stats["input_lra"], 0, 99, name="input_lra"
|
|
525
512
|
),
|
|
526
513
|
"measured_tp": self._constrain(
|
|
527
|
-
|
|
514
|
+
stats["input_tp"], -99, 99, name="input_tp"
|
|
528
515
|
),
|
|
529
516
|
"measured_thresh": self._constrain(
|
|
530
|
-
|
|
517
|
+
stats["input_thresh"], -99, 0, name="input_thresh"
|
|
531
518
|
),
|
|
532
519
|
"linear": "false" if self.media_file.ffmpeg_normalize.dynamic else "true",
|
|
533
520
|
"print_format": "json",
|
ffmpeg_normalize/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.
|
|
1
|
+
__version__ = "1.31.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ffmpeg-normalize
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.31.0
|
|
4
4
|
Summary: Normalize audio via ffmpeg
|
|
5
5
|
Home-page: https://github.com/slhck/ffmpeg-normalize
|
|
6
6
|
Author: Werner Robitza
|
|
@@ -15,12 +15,12 @@ Classifier: Topic :: Multimedia :: Sound/Audio :: Conversion
|
|
|
15
15
|
Classifier: License :: OSI Approved :: MIT License
|
|
16
16
|
Classifier: Natural Language :: English
|
|
17
17
|
Classifier: Programming Language :: Python :: 3
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.9
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
-
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
Requires-Dist: tqdm
|
|
@@ -35,7 +35,7 @@ Requires-Dist: colorama; platform_system == "Windows"
|
|
|
35
35
|

|
|
36
36
|
|
|
37
37
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
38
|
-
[](#contributors-)
|
|
39
39
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
40
40
|
|
|
41
41
|
A utility for batch-normalizing audio using ffmpeg.
|
|
@@ -58,6 +58,7 @@ Read on for more info.
|
|
|
58
58
|
- [Requirements](#requirements)
|
|
59
59
|
- [ffmpeg](#ffmpeg)
|
|
60
60
|
- [Installation](#installation)
|
|
61
|
+
- [Shell Completions](#shell-completions)
|
|
61
62
|
- [Usage with Docker](#usage-with-docker)
|
|
62
63
|
- [High LeveL Introduction](#high-level-introduction)
|
|
63
64
|
- [Basic Usage](#basic-usage)
|
|
@@ -73,6 +74,7 @@ Read on for more info.
|
|
|
73
74
|
- [Environment Variables](#environment-variables)
|
|
74
75
|
- [API](#api)
|
|
75
76
|
- [FAQ](#faq)
|
|
77
|
+
- [My output file is too large?](#my-output-file-is-too-large)
|
|
76
78
|
- [What options should I choose for the EBU R128 filter? What is linear and dynamic mode?](#what-options-should-i-choose-for-the-ebu-r128-filter-what-is-linear-and-dynamic-mode)
|
|
77
79
|
- [The program doesn't work because the "loudnorm" filter can't be found](#the-program-doesnt-work-because-the-loudnorm-filter-cant-be-found)
|
|
78
80
|
- [Should I use this to normalize my music collection?](#should-i-use-this-to-normalize-my-music-collection)
|
|
@@ -92,7 +94,7 @@ Read on for more info.
|
|
|
92
94
|
|
|
93
95
|
## Requirements
|
|
94
96
|
|
|
95
|
-
You need Python 3.
|
|
97
|
+
You need Python 3.9 or higher, and ffmpeg.
|
|
96
98
|
|
|
97
99
|
### ffmpeg
|
|
98
100
|
|
|
@@ -133,6 +135,54 @@ Or download this repository, then run `pip3 install .`.
|
|
|
133
135
|
|
|
134
136
|
To later upgrade to the latest version, run `pip3 install --upgrade ffmpeg-normalize`.
|
|
135
137
|
|
|
138
|
+
### Shell Completions
|
|
139
|
+
|
|
140
|
+
This tool provides shell completions for bash and zsh. To install them:
|
|
141
|
+
|
|
142
|
+
<!--
|
|
143
|
+
Note to self: Generate the shtab ones with:
|
|
144
|
+
|
|
145
|
+
shtab --shell=bash -u ffmpeg_normalize.__main__.create_parser > completions/ffmpeg-normalize-shtab.bash
|
|
146
|
+
shtab --shell=zsh -u ffmpeg_normalize.__main__.create_parser > completions/ffmpeg-normalize-shtab.zsh
|
|
147
|
+
|
|
148
|
+
but these are not properly working yet.
|
|
149
|
+
-->
|
|
150
|
+
|
|
151
|
+
#### Bash
|
|
152
|
+
|
|
153
|
+
If you have [`bash-completion`](https://github.com/scop/bash-completion) installed, you can just copy your new completion script to the `/usr/local/etc/bash_completion.d` directory.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
curl -L https://raw.githubusercontent.com/slhck/ffmpeg-normalize/master/completions/ffmpeg-normalize-completion.bash \
|
|
157
|
+
-o /usr/local/etc/bash_completion.d/ffmpeg-normalize
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Without bash-completion, you can manually install the completion script:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# create completions directory if it doesn't exist
|
|
164
|
+
mkdir -p ~/.bash_completions.d
|
|
165
|
+
|
|
166
|
+
# download and install completion script
|
|
167
|
+
curl -L https://raw.githubusercontent.com/slhck/ffmpeg-normalize/master/completions/ffmpeg-normalize-completion.bash \
|
|
168
|
+
-o ~/.bash_completions.d/ffmpeg-normalize
|
|
169
|
+
|
|
170
|
+
# source it in your ~/.bashrc
|
|
171
|
+
echo 'source ~/.bash_completions.d/ffmpeg-normalize' >> ~/.bashrc
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### Zsh
|
|
175
|
+
|
|
176
|
+
Download the completion script and place it in the default `site-functions` directory:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
curl -L https://raw.githubusercontent.com/slhck/ffmpeg-normalize/master/completions/ffmpeg-normalize.zsh \
|
|
180
|
+
-o /usr/local/share/zsh/site-functions/
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
You may choose any other directory that is in your `$FPATH` variable.
|
|
184
|
+
Make sure your `.zshrc` file contains `autoload -Uz compinit && compinit`.
|
|
185
|
+
|
|
136
186
|
## Usage with Docker
|
|
137
187
|
|
|
138
188
|
You can use the pre-built image from Docker Hub:
|
|
@@ -284,10 +334,7 @@ For more information on the options (`[options]`) available, run `ffmpeg-normali
|
|
|
284
334
|
|
|
285
335
|
- `--keep-lra-above-loudness-range-target`: Keep input loudness range above loudness range target.
|
|
286
336
|
|
|
287
|
-
|
|
288
|
-
- keep input loudness range target above `LOUDNESS_RANGE_TARGET`.
|
|
289
|
-
|
|
290
|
-
as alternative to `--keep-loudness-range-target` to allow for linear normalization.
|
|
337
|
+
Can be used as an alternative to `--keep-loudness-range-target` to allow for linear normalization.
|
|
291
338
|
|
|
292
339
|
- `-tp TRUE_PEAK, --true-peak TRUE_PEAK`: EBU Maximum True Peak in dBTP (default: -2.0).
|
|
293
340
|
|
|
@@ -299,6 +346,16 @@ For more information on the options (`[options]`) available, run `ffmpeg-normali
|
|
|
299
346
|
|
|
300
347
|
Range is -99.0 - +99.0.
|
|
301
348
|
|
|
349
|
+
- `--lower-only`: Whether the audio should not increase in loudness.
|
|
350
|
+
|
|
351
|
+
If the measured loudness from the first pass is lower than the target loudness then normalization pass will be skipped for the measured audio source.
|
|
352
|
+
|
|
353
|
+
- `--auto-lower-loudness-target`: Automatically lower EBU Integrated Loudness Target.
|
|
354
|
+
|
|
355
|
+
Automatically lower EBU Integrated Loudness Target to prevent falling back to dynamic filtering.
|
|
356
|
+
|
|
357
|
+
Makes sure target loudness is lower than measured loudness minus peak loudness (input_i - input_tp) by a small amount.
|
|
358
|
+
|
|
302
359
|
- `--dual-mono`: Treat mono input files as "dual-mono".
|
|
303
360
|
|
|
304
361
|
If a mono file is intended for playback on a stereo system, its EBU R128 measurement will be perceptually incorrect. If set, this option will compensate for this effect. Multi-channel input files are not affected by this option.
|
|
@@ -307,7 +364,7 @@ For more information on the options (`[options]`) available, run `ffmpeg-normali
|
|
|
307
364
|
|
|
308
365
|
Instead of applying linear EBU R128 normalization, choose a dynamic normalization. This is not usually recommended.
|
|
309
366
|
|
|
310
|
-
Dynamic mode will automatically change the sample rate to 192 kHz. Use
|
|
367
|
+
Dynamic mode will automatically change the sample rate to 192 kHz. Use `-ar`/`--sample-rate` to specify a different output sample rate.
|
|
311
368
|
|
|
312
369
|
### Audio Encoding
|
|
313
370
|
|
|
@@ -409,6 +466,16 @@ For more information see the [API documentation](https://htmlpreview.github.io/?
|
|
|
409
466
|
|
|
410
467
|
## FAQ
|
|
411
468
|
|
|
469
|
+
### My output file is too large?
|
|
470
|
+
|
|
471
|
+
This is because the default output codec is PCM, which is uncompressed. If you want to reduce the file size, you can specify an audio codec with `-c:a` (e.g., `-c:a aac` for ffmpeg's built-in AAC encoder), and optionally a bitrate with `-b:a`.
|
|
472
|
+
|
|
473
|
+
For example:
|
|
474
|
+
|
|
475
|
+
```bash
|
|
476
|
+
ffmpeg-normalize input.wav -o output.m4a -c:a aac -b:a 192k
|
|
477
|
+
```
|
|
478
|
+
|
|
412
479
|
### What options should I choose for the EBU R128 filter? What is linear and dynamic mode?
|
|
413
480
|
|
|
414
481
|
EBU R128 is a method for normalizing audio loudness across different tracks or programs. It works by analyzing the audio content and adjusting it to meet specific loudness targets. The main components are:
|
|
@@ -433,7 +500,11 @@ For most cases, linear mode is recommended. Dynamic mode should only be used whe
|
|
|
433
500
|
|
|
434
501
|
* When the required gain adjustment to meet the integrated loudness target would result in the true peak exceeding the specified true peak limit. This is because linear processing alone cannot reduce peaks without affecting the entire signal. For example, if a file needs to be amplified by 6 dB to reach the target integrated loudness, but doing so would push the true peak above the specified limit, the filter might switch to dynamic mode to handle this situation. If your content allows for it, you can increase the true peak target to give more headroom for linear processing. If you're consistently running into true peak issues, you might also consider lowering your target integrated loudness level.
|
|
435
502
|
|
|
436
|
-
At this time, the `loudnorm` filter in ffmpeg does not provide a way to force linear mode when the input loudness range exceeds the target or when the true peak would be exceeded.
|
|
503
|
+
At this time, the `loudnorm` filter in ffmpeg does not provide a way to force linear mode when the input loudness range exceeds the target or when the true peak would be exceeded. There are some options to mitigate this:
|
|
504
|
+
|
|
505
|
+
- The `--keep-lra-above-loudness-range-target` option can be used to keep the input loudness range above the specified target, but it will not force linear mode in all cases.
|
|
506
|
+
- Similarly, the `--keep-loudness-range-target` option can be used to keep the input loudness range target.
|
|
507
|
+
- The `--lower-only` option can be used to skip the normalization pass completely if the measured loudness is lower than the target loudness.
|
|
437
508
|
|
|
438
509
|
### The program doesn't work because the "loudnorm" filter can't be found
|
|
439
510
|
|
|
@@ -552,6 +623,7 @@ If you found this program useful and feel like giving back, feel free to send a
|
|
|
552
623
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/psavva"><img src="https://avatars.githubusercontent.com/u/1454758?v=4?s=100" width="100px;" alt="Panayiotis Savva"/><br /><sub><b>Panayiotis Savva</b></sub></a><br /><a href="https://github.com/slhck/ffmpeg-normalize/commits?author=psavva" title="Code">💻</a></td>
|
|
553
624
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/HighMans"><img src="https://avatars.githubusercontent.com/u/42877729?v=4?s=100" width="100px;" alt="HighMans"/><br /><sub><b>HighMans</b></sub></a><br /><a href="https://github.com/slhck/ffmpeg-normalize/commits?author=HighMans" title="Code">💻</a></td>
|
|
554
625
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kanjieater"><img src="https://avatars.githubusercontent.com/u/32607317?v=4?s=100" width="100px;" alt="kanjieater"/><br /><sub><b>kanjieater</b></sub></a><br /><a href="#ideas-kanjieater" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
626
|
+
<td align="center" valign="top" width="14.28%"><a href="https://ahmetsait.com/"><img src="https://avatars.githubusercontent.com/u/8372246?v=4?s=100" width="100px;" alt="Ahmet Sait"/><br /><sub><b>Ahmet Sait</b></sub></a><br /><a href="https://github.com/slhck/ffmpeg-normalize/commits?author=ahmetsait" title="Code">💻</a></td>
|
|
555
627
|
</tr>
|
|
556
628
|
</tbody>
|
|
557
629
|
<tfoot>
|
|
@@ -599,6 +671,44 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
599
671
|
# Changelog
|
|
600
672
|
|
|
601
673
|
|
|
674
|
+
## v1.31.0 (2024-12-15)
|
|
675
|
+
|
|
676
|
+
* Update docs and completions.
|
|
677
|
+
|
|
678
|
+
* Implement `--auto-lower-loudness-target`
|
|
679
|
+
|
|
680
|
+
* Fix deprecations and mypy --strict errors.
|
|
681
|
+
|
|
682
|
+
* Feat: add completions.
|
|
683
|
+
|
|
684
|
+
* Docs: update explainer.
|
|
685
|
+
|
|
686
|
+
* Docs: update docs to include lower-only.
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
## v1.30.0 (2024-11-22)
|
|
690
|
+
|
|
691
|
+
* Change lower-only message to warning.
|
|
692
|
+
|
|
693
|
+
* Make setup name PEP 625 compliant.
|
|
694
|
+
|
|
695
|
+
* Docs: add @ahmetsait as a contributor.
|
|
696
|
+
|
|
697
|
+
* Implement `--lower-only`
|
|
698
|
+
|
|
699
|
+
* Fix: `--print-stats` only outputs the last stream.
|
|
700
|
+
|
|
701
|
+
* More robust `loudnorm` output parsing.
|
|
702
|
+
|
|
703
|
+
* Remove unnecessary conversions.
|
|
704
|
+
|
|
705
|
+
* Update .editorconfig.
|
|
706
|
+
|
|
707
|
+
* Remove python 3.8, add python 3.12, 3.13.
|
|
708
|
+
|
|
709
|
+
* Add README on file size.
|
|
710
|
+
|
|
711
|
+
|
|
602
712
|
## v1.29.2 (2024-11-18)
|
|
603
713
|
|
|
604
714
|
* Fix: show percentage with two decimal digits in progress.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
ffmpeg_normalize/__init__.py,sha256=aAhlk93ZE6SQcWUDzZQcw9vJh0bJcKEUNFGhVc5ZIto,453
|
|
2
|
+
ffmpeg_normalize/__main__.py,sha256=AuyIcMU1WxGamczZtZyISfgMsEIt3Y1kSJ87dCoH9J4,19393
|
|
3
|
+
ffmpeg_normalize/_cmd_utils.py,sha256=S7PLXQAZHmJ30RM9K6b--vXuxMf-cQHtaFOPtILxz-4,5360
|
|
4
|
+
ffmpeg_normalize/_errors.py,sha256=brTQ4osJ4fTA8wnyMPVVYfGwJ0wqeShRFydTEwi_VEY,48
|
|
5
|
+
ffmpeg_normalize/_ffmpeg_normalize.py,sha256=VoxhER57Ew0RKC_WcGpoCmyKKoqsHYuqNFMm7z4BPM4,11080
|
|
6
|
+
ffmpeg_normalize/_logger.py,sha256=3Ap4Fxg7xGrzz7h4IGuNEf0KKstx0Rq_eLbHPrHzcrI,1841
|
|
7
|
+
ffmpeg_normalize/_media_file.py,sha256=KUAjyI5hAGv5M-Y7NurrS8nmH0gelgIfw9CbLYWOWf8,17972
|
|
8
|
+
ffmpeg_normalize/_streams.py,sha256=LIllXl4SKLxlyPVjD3ieHqc_byF2eUTjnK-clh2g_CY,20211
|
|
9
|
+
ffmpeg_normalize/_version.py,sha256=jYtGJTa-bBcDTtE3IrYQBdcmjbk5Cfx7X6sxv2dEPwg,23
|
|
10
|
+
ffmpeg_normalize/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
ffmpeg_normalize-1.31.0.dist-info/LICENSE,sha256=zeqAHGWrSIwdPHsZMZv1_N0gGFO1xxjcZEz9CplR4EM,1086
|
|
12
|
+
ffmpeg_normalize-1.31.0.dist-info/METADATA,sha256=TaXepF_i6VrztwLBsg8SEik_g3TOss4RQSTuX0RuUqI,60081
|
|
13
|
+
ffmpeg_normalize-1.31.0.dist-info/WHEEL,sha256=fS9sRbCBHs7VFcwJLnLXN1MZRR0_TVTxvXKzOnaSFs8,110
|
|
14
|
+
ffmpeg_normalize-1.31.0.dist-info/entry_points.txt,sha256=X0EC5ptb0iGOxrk3Aa65dVQtvUixngLd_2-iAtSixdc,68
|
|
15
|
+
ffmpeg_normalize-1.31.0.dist-info/top_level.txt,sha256=wnUkr17ckPrrU1JsxZQiXbEBUnHKsC64yck-MemEBuI,17
|
|
16
|
+
ffmpeg_normalize-1.31.0.dist-info/RECORD,,
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
ffmpeg_normalize/__init__.py,sha256=aAhlk93ZE6SQcWUDzZQcw9vJh0bJcKEUNFGhVc5ZIto,453
|
|
2
|
-
ffmpeg_normalize/__main__.py,sha256=vIVZAKPyI7zO9K22FYeaE-q_4JeZAQg1xlQc0739Gqk,18603
|
|
3
|
-
ffmpeg_normalize/_cmd_utils.py,sha256=A6quxjOl5tLHxgcs7SdMXzuOCP_JjUTzL1iUD4G7DJk,5361
|
|
4
|
-
ffmpeg_normalize/_errors.py,sha256=brTQ4osJ4fTA8wnyMPVVYfGwJ0wqeShRFydTEwi_VEY,48
|
|
5
|
-
ffmpeg_normalize/_ffmpeg_normalize.py,sha256=mARUHvgLwcs0yGsuDkkDZYqE2JJmnEZtkADKUS4giRc,10556
|
|
6
|
-
ffmpeg_normalize/_logger.py,sha256=3Ap4Fxg7xGrzz7h4IGuNEf0KKstx0Rq_eLbHPrHzcrI,1841
|
|
7
|
-
ffmpeg_normalize/_media_file.py,sha256=ym9t_J3Z_jCiL0YMGwk0-E0o3qg858d4-3JX7hAiFmk,16651
|
|
8
|
-
ffmpeg_normalize/_streams.py,sha256=5zLlSK2vMTBs0HzBTmI5UiJVqSp1Nk19TZXpxNtjkIA,19973
|
|
9
|
-
ffmpeg_normalize/_version.py,sha256=x7VlhF5gtHvQF5azFyGSActBYj8D2TvquvRXi3DdQdA,23
|
|
10
|
-
ffmpeg_normalize/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
ffmpeg_normalize-1.29.2.dist-info/LICENSE,sha256=zeqAHGWrSIwdPHsZMZv1_N0gGFO1xxjcZEz9CplR4EM,1086
|
|
12
|
-
ffmpeg_normalize-1.29.2.dist-info/METADATA,sha256=En7t5Ll7zA6K2mbO9nCu5DqjZhHZJlyIPHZlZoW-N6M,56315
|
|
13
|
-
ffmpeg_normalize-1.29.2.dist-info/WHEEL,sha256=fS9sRbCBHs7VFcwJLnLXN1MZRR0_TVTxvXKzOnaSFs8,110
|
|
14
|
-
ffmpeg_normalize-1.29.2.dist-info/entry_points.txt,sha256=X0EC5ptb0iGOxrk3Aa65dVQtvUixngLd_2-iAtSixdc,68
|
|
15
|
-
ffmpeg_normalize-1.29.2.dist-info/top_level.txt,sha256=wnUkr17ckPrrU1JsxZQiXbEBUnHKsC64yck-MemEBuI,17
|
|
16
|
-
ffmpeg_normalize-1.29.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|