Files
DepressedCat 5f2aad00f4
Check extension and helper / check (push) Canceled after 0s
Publish YouTubeDL 1.4.5 and website on Gitea
2026-10-10 23:53:17 +03:00

34 lines
2.0 KiB
Python

"""On this NVIDIA machine: real AMF initialization failure and automatic CPU fallback."""
import contextlib
import io
import json
import subprocess
import sys
from pathlib import Path
PROJECT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT))
from host.media import capabilities, probe, tool
from host.worker import convert
hardware = capabilities()
if hardware["amf"]:
raise RuntimeError("This negative-path check is intended for a machine without AMD AMF.")
folder = PROJECT / "test-artifacts/media"; folder.mkdir(parents=True, exist_ok=True)
source = folder / "amd-fallback-input.mkv"
subprocess.run([tool("ffmpeg"), "-hide_banner", "-loglevel", "error", "-y", "-f", "lavfi", "-i", "testsrc2=s=320x180:r=24", "-f", "lavfi", "-i", "sine=frequency=440", "-t", "0.4", "-c:v", "libx264", "-c:a", "aac", str(source)], check=True, capture_output=True)
media = probe(source)
options = {"mode": "video", "container": "mp4", "codec": "hevc", "engine": "auto", "preset": "fast", "bitrate": 192}
events = io.StringIO()
with contextlib.redirect_stdout(events):
plan = convert(source, folder / "amd-fallback-result.mp4", options, media, {"amf": ["hevc"]})
assert plan["engine"] == "cpu"
assert {item["codec_type"] for item in probe(folder / "amd-fallback-result.mp4")["streams"]} == {"video", "audio"}
with contextlib.redirect_stdout(io.StringIO()):
try: convert(source, folder / "amd-forced-result.mp4", {**options, "engine": "amf"}, media, {"amf": ["hevc"]})
except ValueError as error: assert "FFmpeg" in str(error)
else: raise AssertionError("Forced AMD mode must not silently use the CPU")
report = {"gpu": hardware["gpu"], "amfMeasured": hardware["amf"], "nvencMeasured": hardware["nvenc"], "autoFallback": "CPU passed", "forcedAMF": "rejected", "physicalAMDEncoding": "not tested: AMD GPU absent"}
(PROJECT / "test-artifacts/amd-fallback.json").write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
print("AMD negative-path checks passed: real AMF failure, automatic CPU fallback with audio, and forced-mode error.")