Disallow setting unsupported vcodec.

This commit is contained in:
arabcoders 2025-09-16 16:02:38 +03:00
parent 215a023da8
commit 314752a644
4 changed files with 13 additions and 11 deletions

View file

@ -34,6 +34,7 @@
"Cfmrc", "Cfmrc",
"choco", "choco",
"cifs", "cifs",
"connectionpool",
"consoletitle", "consoletitle",
"continuedl", "continuedl",
"cookiesfrombrowser", "cookiesfrombrowser",

View file

@ -7,9 +7,6 @@ import sys
from pathlib import Path from pathlib import Path
from typing import Any, Protocol from typing import Any, Protocol
SUPPORTED_CODECS: tuple[str] = ("h264_qsv", "h264_nvenc", "h264_amf", "h264_videotoolbox", "h264_vaapi", "libx264")
"Supported encoder names in order of preference."
def has_dri_devices() -> bool: def has_dri_devices() -> bool:
""" """
@ -40,6 +37,7 @@ def ffmpeg_encoders() -> set[str]:
set[str]: A set of available ffmpeg encoder names. set[str]: A set of available ffmpeg encoder names.
""" """
from .config import SUPPORTED_CODECS
try: try:
result: subprocess.CompletedProcess[str] = subprocess.run( result: subprocess.CompletedProcess[str] = subprocess.run(
["ffmpeg", "-hide_banner", "-loglevel", "error", "-encoders"], # noqa: S607 ["ffmpeg", "-hide_banner", "-loglevel", "error", "-encoders"], # noqa: S607
@ -75,6 +73,7 @@ def select_encoder(configured: str) -> str:
str: The selected concrete encoder name. str: The selected concrete encoder name.
""" """
from .config import SUPPORTED_CODECS
configured = (configured or "").strip() configured = (configured or "").strip()
avail: set[str] = ffmpeg_encoders() avail: set[str] = ffmpeg_encoders()

View file

@ -10,15 +10,9 @@ from typing import TYPE_CHECKING, Any, ClassVar
from aiohttp import web from aiohttp import web
from .config import Config from .config import SUPPORTED_CODECS, Config
from .ffprobe import ffprobe from .ffprobe import ffprobe
from .SegmentEncoders import ( from .SegmentEncoders import encoder_fallback_chain, get_builder_for_codec, has_dri_devices, select_encoder
SUPPORTED_CODECS,
encoder_fallback_chain,
get_builder_for_codec,
has_dri_devices,
select_encoder,
)
if TYPE_CHECKING: if TYPE_CHECKING:
from asyncio.subprocess import Process from asyncio.subprocess import Process

View file

@ -19,6 +19,9 @@ from .version import APP_BRANCH, APP_BUILD_DATE, APP_COMMIT_SHA, APP_VERSION
if TYPE_CHECKING: if TYPE_CHECKING:
from subprocess import CompletedProcess from subprocess import CompletedProcess
SUPPORTED_CODECS: tuple[str] = ("h264_qsv", "h264_nvenc", "h264_amf", "h264_videotoolbox", "h264_vaapi", "libx264")
"Supported encoder names in order of preference."
class Config(metaclass=Singleton): class Config(metaclass=Singleton):
app_env: str = "production" app_env: str = "production"
@ -417,6 +420,11 @@ class Config(metaclass=Singleton):
msg: str = f"Invalid app environment '{self.app_env}' specified. Must be 'production' or 'development'." msg: str = f"Invalid app environment '{self.app_env}' specified. Must be 'production' or 'development'."
raise ValueError(msg) raise ValueError(msg)
if self.streamer_vcodec and self.streamer_vcodec not in SUPPORTED_CODECS:
supported = ", ".join(SUPPORTED_CODECS)
msg: str = f"Invalid video codec '{self.streamer_vcodec}' specified. Supported: '{supported}'."
raise ValueError(msg)
if "dev-master" == self.app_version: if "dev-master" == self.app_version:
self._version_via_git() self._version_via_git()