fix(transcode): only pick a GPU encoder when its device is present#5
Merged
Conversation
…resent detect_hw_encoder() in 'auto' mode picked nvenc as soon as ffmpeg *listed* h264_nvenc — even on a host with no NVIDIA GPU. The encoder is compiled into many ffmpeg builds, so on a GPU-less server transcoding failed at runtime with "[h264_nvenc] Cannot load libcuda.so.1 / Error initializing output stream", and the player showed "invalid video source". Observed in production (no GPU, ffmpeg shipping nvenc). Now nvenc requires a real NVIDIA device (/dev/nvidia0 or /dev/nvidiactl) and v4l2m2m requires /dev/video10 — mirroring the device check VAAPI already does. 'auto' falls back to software (libx264) when no usable device exists. Explicit FFMPEG_HW_ACCEL still forces a backend for non-standard setups. Added HwAccelTest::testGpuBackendChosenOnlyWhenDevicePresent locking the invariant. phpunit 442/887 green, PHPStan clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
On a server without an NVIDIA GPU, transcoding fails and the player shows "invalid video source / server unreachable." The stream log shows
hw=nvenc, and ffmpeg's error log:Root cause
detect_hw_encoder()inautomode pickednvencas soon asffmpeg -encoderslistedh264_nvenc— but that encoder is compiled into many ffmpeg builds regardless of hardware. So on a GPU-less host it chose nvenc, which then failed at runtime (nolibcuda.so.1). VAAPI already guarded on its device file; nvenc and v4l2m2m didn't.Fix
nvencnow requires a real device:/dev/nvidia0or/dev/nvidiactl.v4l2m2mnow requires/dev/video10and the encoder (was||).autocorrectly falls back to software (libx264) when no usable device exists.FFMPEG_HW_ACCEL=nvenc|vaapi|v4l2m2mstill forces a backend for non-standard setups (the override path is unchanged).Added
HwAccelTest::testGpuBackendChosenOnlyWhenDevicePresent— would have failed before this fix on the affected server.phpunit 442/887 green · PHPStan level 5 clean.
🤖 Generated with Claude Code