Skip to content

obs-ffmpeg: Fall back to a working VAAPI device - #198

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/197-vaapi-stale-device
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/197-vaapi-stale-device

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Description

The FFmpeg VAAPI encoders failed to start when the profile's saved vaapi_device wasn't usable on this machine, with only Failed to create VAAPI device context: Invalid argument in 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 to av_hwdevice_ctx_create(). The default device is only set with obs_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.

  1. test/cmocka: Add RED VAAPI stale device tests: moves the choice, unchanged, into vaapi_select_device() in plugins/obs-ffmpeg/vaapi-device-select.c (no libva or FFmpeg calls; usability is a callback, wired to the existing codec support probe) and adds test_vaapi_device_select. 5 of its 7 tests fail on this commit:
    • test_missing_render_node_falls_back
    • test_other_machines_by_path_device_falls_back
    • test_unusable_existing_node_falls_back
    • test_unusable_candidates_are_skipped
    • test_empty_device_uses_working_node
    • test_working_configured_device_is_kept and test_nothing_usable_keeps_configured pass: a working configured device is used as is, and with nothing usable the encoder fails as before.
  2. 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 warn Device '<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_select fails 5 of 7 at the RED commit and passes 7 of 7 at the GREEN commit (built and run on Arch Linux). The obs-ffmpeg plugin 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_tex and hevc_ffmpeg_vaapi:

vaapi_device before after
missing render node (/dev/dri/renderD129) fails, Invalid argument falls back, 60 frames
by-path node of another PCI slot fails, Invalid argument falls back, 60 frames
primary node the user can't open (/dev/dri/card0) fails, Invalid argument falls back, 60 frames
/dev/null fails, Generic error in an external library falls back, 60 frames
empty string fails, Input/output error / Invalid argument falls back, 60 frames
unset, or the real render node 60 frames unchanged

Note 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:

  • NVIDIA (nvidia-vaapi-driver) or Intel VAAPI.
  • A real X/Xwayland session with DRI3, where "" might still resolve through the X11 path.
  • The Rust and Docker lanes of the local gate.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

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]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 11, 2026 05:06
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"}
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped. The new head is 5fccaf363.

  • RED (b7c41b839): Tier 2 passed 60 of 61. test_vaapi_device_select failed 5 of 7.
  • GREEN (33f589ede): Tier 2 passed 61 of 61 with ENABLE_RUST_LIBOBS OFF and 61 of 61 with it ON.
  • Local gate: lint, rust-test and tier2-linux all passed.

Note: the configured device is now probed with vaapi_device_codec_supported on every encoder start. That costs one extra device open, which is fine. Merging once CI is green.

@zackees
zackees force-pushed the fix/197-vaapi-stale-device branch from 33f589e to 5fccaf3 Compare October 11, 2026 05:13
@zackees
zackees merged commit 5ffe511 into obs-rust:master Oct 11, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: obs-ffmpeg: VAAPI encoders fail to start on a stale vaapi_device instead of falling back (upstream #13773)

2 participants