@@ -880,17 +880,50 @@ def _second_pass(self) -> Iterator[float]:
880880 "This can happen when normalization is skipped (e.g., with --lower-only)."
881881 )
882882
883- # warn if self.media_file.ffmpeg_normalize. dynamic == False and any of the second pass stats contain "normalization_type" == "dynamic"
883+ # warn if dynamic == False and any of the second pass stats contain "normalization_type" == "dynamic"
884884 if self .ffmpeg_normalize .dynamic is False :
885885 for audio_stream in self .streams ["audio" ].values ():
886886 pass2_stats = audio_stream .get_stats ()["ebu_pass2" ]
887887 if pass2_stats is None :
888888 continue
889889 if pass2_stats ["normalization_type" ] == "dynamic" :
890+ pass1_stats = audio_stream .get_stats ()["ebu_pass1" ]
891+
892+ reason = ""
893+ if pass1_stats is not None :
894+ linear_gain = (
895+ self .ffmpeg_normalize .target_level - pass1_stats ["input_i" ]
896+ )
897+ estimated_tp = pass1_stats ["input_tp" ] + linear_gain
898+ if estimated_tp > self .ffmpeg_normalize .true_peak :
899+ min_tp = estimated_tp
900+ max_target = (
901+ self .ffmpeg_normalize .true_peak
902+ - pass1_stats ["input_tp" ]
903+ + pass1_stats ["input_i" ]
904+ )
905+ reason = (
906+ f" Reason: the input true peak ({ pass1_stats ['input_tp' ]:.2f} dBTP) is too high — "
907+ f"after linear gain of { linear_gain :.2f} dB, "
908+ f"the estimated true peak would be { estimated_tp :.2f} dBTP, "
909+ f"exceeding the target of { self .ffmpeg_normalize .true_peak } dBTP. "
910+ f"To avoid this, raise --true-peak (-tp) to at least { min_tp :.1f} , "
911+ f"or lower the target level (-t) to at most { max_target :.1f} ."
912+ )
913+ elif (
914+ pass1_stats ["input_lra" ]
915+ > self .ffmpeg_normalize .loudness_range_target
916+ ):
917+ reason = (
918+ f" Reason: the input loudness range ({ pass1_stats ['input_lra' ]:.2f} LU) "
919+ f"exceeds the target ({ self .ffmpeg_normalize .loudness_range_target :.2f} LU). "
920+ "Consider raising the target loudness range or using "
921+ "--keep-loudness-range-target / --keep-lra-above-loudness-range-target."
922+ )
923+
890924 _logger .warning (
891- f"{ self .input_file } : You specified linear normalization, but the loudnorm filter reverted to dynamic normalization. "
892- "This may lead to unexpected results. "
893- "Consider your input settings, e.g. choose a lower target level or higher target loudness range."
925+ f"{ self .input_file } : You specified linear normalization, but the loudnorm filter "
926+ f"reverted to dynamic normalization.{ reason } "
894927 )
895928
896929 _logger .debug ("Normalization finished" )
0 commit comments