44import logging
55import os
66import re
7- from typing import TYPE_CHECKING , Iterator , List , Literal , Optional , TypedDict , cast
7+ from typing import TYPE_CHECKING , Iterator , Literal , TypedDict , cast
88
9- from ._cmd_utils import NUL , CommandRunner , dict_to_filter_opts
9+ from ._cmd_utils import CommandRunner , dict_to_filter_opts
1010from ._errors import FFmpegNormalizeError
1111
1212if TYPE_CHECKING :
1717
1818_loudnorm_pattern = re .compile (r"\[Parsed_loudnorm_(\d+)" )
1919
20+
2021class EbuLoudnessStatistics (TypedDict ):
2122 input_i : float
2223 input_tp : float
@@ -239,7 +240,7 @@ def parse_astats(self) -> Iterator[float]:
239240 "-sn" ,
240241 "-f" ,
241242 "null" ,
242- NUL ,
243+ os . devnull ,
243244 ]
244245
245246 cmd_runner = CommandRunner ()
@@ -310,7 +311,7 @@ def parse_loudnorm_stats(self) -> Iterator[float]:
310311 "-sn" ,
311312 "-f" ,
312313 "null" ,
313- NUL ,
314+ os . devnull ,
314315 ]
315316
316317 cmd_runner = CommandRunner ()
@@ -322,11 +323,13 @@ def parse_loudnorm_stats(self) -> Iterator[float]:
322323 )
323324
324325 # only one stream
325- self .loudness_statistics ["ebu_pass1" ] = next (iter (AudioStream .prune_and_parse_loudnorm_output (output ).values ()))
326+ self .loudness_statistics ["ebu_pass1" ] = next (
327+ iter (AudioStream .prune_and_parse_loudnorm_output (output ).values ())
328+ )
326329
327330 @staticmethod
328331 def prune_and_parse_loudnorm_output (
329- output : str
332+ output : str ,
330333 ) -> dict [int , EbuLoudnessStatistics ]:
331334 """
332335 Prune ffmpeg progress lines from output and parse the loudnorm filter output.
@@ -344,7 +347,7 @@ def prune_and_parse_loudnorm_output(
344347
345348 @staticmethod
346349 def _parse_loudnorm_output (
347- output_lines : list [str ]
350+ output_lines : list [str ],
348351 ) -> dict [int , EbuLoudnessStatistics ]:
349352 """
350353 Parse the output of a loudnorm filter to get the EBU loudness statistics.
@@ -403,7 +406,9 @@ def _parse_loudnorm_output(
403406 # convert to floats
404407 loudnorm_stats [key ] = float (loudnorm_stats [key ])
405408
406- result [stream_index ] = cast (EbuLoudnessStatistics , loudnorm_stats )
409+ result [stream_index ] = cast (
410+ EbuLoudnessStatistics , loudnorm_stats
411+ )
407412 stream_index = - 1
408413 except Exception as e :
409414 raise FFmpegNormalizeError (
@@ -504,15 +509,11 @@ def get_second_pass_opts_ebu(self) -> str:
504509 "offset" : self ._constrain (
505510 stats ["target_offset" ], - 99 , 99 , name = "target_offset"
506511 ),
507- "measured_i" : self ._constrain (
508- stats ["input_i" ], - 99 , 0 , name = "input_i"
509- ),
512+ "measured_i" : self ._constrain (stats ["input_i" ], - 99 , 0 , name = "input_i" ),
510513 "measured_lra" : self ._constrain (
511514 stats ["input_lra" ], 0 , 99 , name = "input_lra"
512515 ),
513- "measured_tp" : self ._constrain (
514- stats ["input_tp" ], - 99 , 99 , name = "input_tp"
515- ),
516+ "measured_tp" : self ._constrain (stats ["input_tp" ], - 99 , 99 , name = "input_tp" ),
516517 "measured_thresh" : self ._constrain (
517518 stats ["input_thresh" ], - 99 , 0 , name = "input_thresh"
518519 ),
0 commit comments