chore(format): formatting code, fixing error messages and variable names

This commit is contained in:
CarolinePascal
2026-05-05 11:31:23 +02:00
parent 3dc73551dd
commit 9b3c752b64
3 changed files with 7 additions and 12 deletions
+1 -5
View File
@@ -177,10 +177,6 @@ def check_video_encoder_config_pyav(config: VideoEncoderConfig) -> None:
vcodec = config.vcodec vcodec = config.vcodec
options = _get_codec_options_by_name(vcodec) options = _get_codec_options_by_name(vcodec)
if not options: if not options:
logger.warning( raise ValueError(f"Codec {vcodec!r} is not available in the bundled FFmpeg build")
"Codec %r is not available in the bundled FFmpeg build; ",
vcodec,
)
return
_check_pixel_format(config.vcodec, config.pix_fmt) _check_pixel_format(config.vcodec, config.pix_fmt)
_check_codec_options(config.vcodec, config.get_codec_options(), config) _check_codec_options(config.vcodec, config.get_codec_options(), config)
+5 -6
View File
@@ -47,7 +47,7 @@ logger = logging.getLogger(__name__)
# List of hardware encoders to probe for auto-selection. Availability depends on the platform and FFmpeg build. # List of hardware encoders to probe for auto-selection. Availability depends on the platform and FFmpeg build.
# Determines the order of preference for auto-selection when vcodec="auto" is used. # Determines the order of preference for auto-selection when vcodec="auto" is used.
HW_ENCODERS = [ HW_VIDEO_CODECS = [
"h264_videotoolbox", # macOS "h264_videotoolbox", # macOS
"hevc_videotoolbox", # macOS "hevc_videotoolbox", # macOS
"h264_nvenc", # NVIDIA GPU "h264_nvenc", # NVIDIA GPU
@@ -56,7 +56,7 @@ HW_ENCODERS = [
"h264_qsv", # Intel Quick Sync "h264_qsv", # Intel Quick Sync
] ]
VALID_VIDEO_CODECS = {"h264", "hevc", "libsvtav1", "auto"} | set(HW_ENCODERS) VALID_VIDEO_CODECS = {"h264", "hevc", "libsvtav1", "auto"} | set(HW_VIDEO_CODECS)
LIBSVTAV1_DEFAULT_PRESET: int = 12 LIBSVTAV1_DEFAULT_PRESET: int = 12
@@ -126,8 +126,8 @@ class VideoEncoderConfig:
if self.vcodec not in VALID_VIDEO_CODECS: if self.vcodec not in VALID_VIDEO_CODECS:
raise ValueError(f"Invalid vcodec '{self.vcodec}'. Must be one of: {sorted(VALID_VIDEO_CODECS)}") raise ValueError(f"Invalid vcodec '{self.vcodec}'. Must be one of: {sorted(VALID_VIDEO_CODECS)}")
if self.vcodec == "auto": if self.vcodec == "auto":
available = self.detect_available_encoders(HW_ENCODERS) available = self.detect_available_encoders(HW_VIDEO_CODECS)
for encoder in HW_ENCODERS: for encoder in HW_VIDEO_CODECS:
if encoder in available: if encoder in available:
logger.info(f"Auto-selected video codec: {encoder}") logger.info(f"Auto-selected video codec: {encoder}")
self.vcodec = encoder self.vcodec = encoder
@@ -137,13 +137,12 @@ class VideoEncoderConfig:
if self.detect_available_encoders(self.vcodec): if self.detect_available_encoders(self.vcodec):
logger.info(f"Using video codec: {self.vcodec}") logger.info(f"Using video codec: {self.vcodec}")
self.vcodec = self.vcodec
return return
raise ValueError(f"Unsupported video codec: {self.vcodec} with video backend {self.video_backend}") raise ValueError(f"Unsupported video codec: {self.vcodec} with video backend {self.video_backend}")
def get_codec_options( def get_codec_options(
self, encoder_threads: int | None = None, as_strings: bool = False self, encoder_threads: int | None = None, as_strings: bool = False
) -> dict[str, str]: ) -> dict[str, Any]:
"""Translate the tuning fields to codec-specific FFmpeg options. """Translate the tuning fields to codec-specific FFmpeg options.
``VideoEncoderConfig.extra_options`` are merged last but never override a structured field. ``VideoEncoderConfig.extra_options`` are merged last but never override a structured field.
+1 -1
View File
@@ -298,7 +298,7 @@ class TestEncoderDetection:
@require_videotoolbox @require_videotoolbox
def test_auto_picks_videotoolbox_when_available(self): def test_auto_picks_videotoolbox_when_available(self):
"""``h264_videotoolbox`` sits at the top of ``HW_ENCODERS`` so it wins when present.""" """``h264_videotoolbox`` sits at the top of ``HW_VIDEO_CODECS`` so it wins when present."""
cfg = VideoEncoderConfig(vcodec="auto") cfg = VideoEncoderConfig(vcodec="auto")
assert cfg.vcodec == "h264_videotoolbox" assert cfg.vcodec == "h264_videotoolbox"