Repository navigation
obs-ffmpeg: Fall back to a working VAAPI device - #198
Merged
Merged
Conversation
The FFmpeg VAAPI encoders fail to start when the profile names a device that is not usable on this machine (obsproject/obs-studio#13773): Failed to create VAAPI device context: Invalid argument vaapi_update() hands the saved vaapi_device straight to av_hwdevice_ctx_create() and gives up when that fails. A profile keeps the path the user picked, so it goes stale when the profile is used on another machine, a second GPU is removed, or a driver change renumbers the render nodes. The default device (the first render node that encodes the codec) only applies while the setting is unset. Reproduced with libobs on a Radeon 680M (radeonsi), encoding a color source with ffmpeg_vaapi, ffmpeg_vaapi_tex and hevc_ffmpeg_vaapi: a missing render node, a by-path node of another PCI slot and a primary node the user cannot open all fail with EINVAL, /dev/null with "Generic error in an external library", and an empty setting with EIO or EINVAL (FFmpeg treats "" as an X11 display or device name, not as "pick one"). The output never starts. With the setting unset or set to the real render node, 60 frames are encoded. Move the choice into obs-ffmpeg/vaapi-device-select.c, without libva or FFmpeg calls, and have vaapi_update() ask it with the codec's default device as the candidate and the existing codec support probe. The function keeps today's behaviour, so 5 of the 7 tests fail: missing_render_node_falls_back, other_machines_by_path_device_falls_back, unusable_existing_node_falls_back, unusable_candidates_are_skipped and empty_device_uses_working_node. The others pin what a fix must keep: a working configured device is used, and with nothing usable the configured device fails as before. Refs obs-rust#197. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
When the saved vaapi_device cannot be opened or does not encode the codec, use the codec's default device (the first render node that does) and log the substitution, instead of failing to start the output (obsproject/obs-studio#13773). A working configured device is still used as is, and with no usable device the encoder fails as before. Probing the configured device adds one libva initialisation when an encoder starts. On a Radeon 680M, ffmpeg_vaapi, ffmpeg_vaapi_tex and hevc_ffmpeg_vaapi now encode 60 frames with a missing render node, a by-path node of another PCI slot, an inaccessible primary node, /dev/null and an empty setting, logging for example: Device '/dev/dri/renderD129' is not usable, falling back to '/dev/dri/renderD128' All 7 tests in test_vaapi_device_select pass. Fixes obs-rust#197. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Local-Gate: v1 tree=f9c2895c659ef07a2d0e884b847b0bd5340c3b30 secs=87 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791695586,"gate":"rust/all/fmt","host":"linux-x86_64","key":"806535844ffbda5b5f280e32cea09799744c41f1fbf81adbd735c4e5e19160d9","lane":"lint","parents":["b7c41b83967cfe2332a77323f861b8cbb07f2390"],"secs":11,"stamp":"25558eff9c6aafd17dae8ce6da1b8064","tree":"f9c2895c659ef07a2d0e884b847b0bd5340c3b30","v":1,"via":"run"} Ci-Attestation: {"at":1791695586,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"806535844ffbda5b5f280e32cea09799744c41f1fbf81adbd735c4e5e19160d9","lane":"lint","parents":["b7c41b83967cfe2332a77323f861b8cbb07f2390"],"secs":11,"stamp":"26b5b3e96b3212ac48ad1b602b701934","tree":"f9c2895c659ef07a2d0e884b847b0bd5340c3b30","v":1,"via":"run"} Ci-Attestation: {"at":1791695586,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"72830ba33d742856f6918c78e9321f4603021f4c8d98f36f88879a5056a058dd","lane":"rust-test","parents":["b7c41b83967cfe2332a77323f861b8cbb07f2390"],"secs":33,"stamp":"1c2b52afd24b9cc1cf757a94bddee152","tree":"f9c2895c659ef07a2d0e884b847b0bd5340c3b30","v":1,"via":"run"} Ci-Attestation: {"at":1791695586,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"1c56a809a5aa0814cf3eb694602c79a69d078b494866d2f4106503f716e561bf","lane":"tier2-linux","parents":["b7c41b83967cfe2332a77323f861b8cbb07f2390"],"secs":43,"stamp":"c145636435182f1416135f07c8bdae3d","tree":"f9c2895c659ef07a2d0e884b847b0bd5340c3b30","v":1,"via":"run"}
Member
|
Verified locally, rebased onto master and stamped. The new head is
Note: the configured device is now probed with |
zackees
force-pushed
the
fix/197-vaapi-stale-device
branch
from
October 11, 2026 05:13
33f589e to
5fccaf3
Compare
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.
Description
The FFmpeg VAAPI encoders failed to start when the profile's saved
vaapi_devicewasn't usable on this machine, with onlyFailed to create VAAPI device context: Invalid argumentin the log. With this change they fall back to the codec's default device (the first render node that encodes the codec) and log the substitution.vaapi_update()handed the saved path straight toav_hwdevice_ctx_create(). The default device is only set withobs_data_set_default_string, so it never replaces a value saved in the profile, and that value goes stale when the profile moves to another machine, a second GPU is removed, or a driver change renumbers the render nodes.test/cmocka: Add RED VAAPI stale device tests: moves the choice, unchanged, intovaapi_select_device()inplugins/obs-ffmpeg/vaapi-device-select.c(no libva or FFmpeg calls; usability is a callback, wired to the existing codec support probe) and addstest_vaapi_device_select. 5 of its 7 tests fail on this commit:test_missing_render_node_falls_backtest_other_machines_by_path_device_falls_backtest_unusable_existing_node_falls_backtest_unusable_candidates_are_skippedtest_empty_device_uses_working_nodetest_working_configured_device_is_keptandtest_nothing_usable_keeps_configuredpass: a working configured device is used as is, and with nothing usable the encoder fails as before.obs-ffmpeg: Fall back to a working VAAPI device: if the configured device is set and usable, use it; otherwise use the first usable candidate and warnDevice '<configured>' is not usable, falling back to '<default>'. All 7 tests pass.Motivation and Context
Fixes #197 (upstream obsproject/obs-studio#13773, reported by chengjilai)
Why this one: a stale device path is easy to end up with and the failure is unhelpful: the UI only says the output failed to start. Copying a profile between machines, removing a GPU or a driver update renumbering render nodes is enough. It has no upstream fix, and the fix is small and keeps a working configuration untouched.
How Has This Been Tested?
Automated:
test_vaapi_device_selectfails 5 of 7 at the RED commit and passes 7 of 7 at the GREEN commit (built and run on Arch Linux). Theobs-ffmpegplugin builds cleanly; clang-format is clean.By hand, with libobs on a Radeon 680M (radeonsi, Mesa 26.2), encoding a color source to MP4 with
ffmpeg_vaapi,ffmpeg_vaapi_texandhevc_ffmpeg_vaapi:vaapi_device/dev/dri/renderD129)Invalid argumentInvalid argument/dev/dri/card0)Invalid argument/dev/nullGeneric error in an external libraryInput/output error/Invalid argumentNote on the upstream report: leaving the setting empty does not make FFmpeg auto-detect; OBS passes
"", which libavutil reads as an X11 display or device name.Cost: one extra libva initialisation (the usability probe) when an encoder starts.
Not tested:
""might still resolve through the X11 path.Types of changes
Checklist:
🤖 Generated with Claude Code