Skip to content

Commit e75b46d

Browse files
committed
fix: bug when first pass stats are skipped
1 parent d57a3f5 commit e75b46d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ repos:
44
hooks:
55
- id: ruff
66
args: [--fix]
7-
- id: ruff-format - repo: https://github.com/commitizen-tools/commitizen
7+
- id: ruff-format
8+
- repo: https://github.com/commitizen-tools/commitizen
89
rev: v4.1.0
910
hooks:
1011
- id: commitizen

src/ffmpeg_normalize/_media_file.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,15 @@ def _second_pass(self) -> Iterator[float]:
645645
ebu_pass_2_stats = list(
646646
AudioStream.prune_and_parse_loudnorm_output(output).values()
647647
)
648-
for idx, audio_stream in enumerate(self.streams["audio"].values()):
649-
audio_stream.set_second_pass_stats(ebu_pass_2_stats[idx])
648+
# Only set second pass stats if they exist (they might not if all streams were skipped with --lower-only)
649+
if len(ebu_pass_2_stats) == len(self.streams["audio"]):
650+
for idx, audio_stream in enumerate(self.streams["audio"].values()):
651+
audio_stream.set_second_pass_stats(ebu_pass_2_stats[idx])
652+
else:
653+
_logger.debug(
654+
f"Expected {len(self.streams['audio'])} EBU pass 2 statistics but got {len(ebu_pass_2_stats)}. "
655+
"This can happen when normalization is skipped (e.g., with --lower-only)."
656+
)
650657

651658
# warn if self.media_file.ffmpeg_normalize.dynamic == False and any of the second pass stats contain "normalization_type" == "dynamic"
652659
if self.ffmpeg_normalize.dynamic is False:

0 commit comments

Comments
 (0)