Skip to content

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

Closed

Description

@rdoupe

Upstream OBS bug, reported by chengjilai in obsproject/obs-studio#13773. Code unchanged in this fork.

Location

plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c: vaapi_update() reads the saved vaapi_device and passes it unchecked to vaapi_init_codec(), which calls

	ret = av_hwdevice_ctx_create(&enc->vadevice_ref, AV_HWDEVICE_TYPE_VAAPI, path, NULL, 0);

and gives up when that fails. The good default (vaapi_get_*_default_device() in vaapi-utils.c, the first render node that encodes the codec) is only set with obs_data_set_default_string, so it never replaces a value saved in the profile.

Class

Logic error: the output fails to start, no fallback.

How it is reached

A profile keeps the device path the user picked. It goes stale when the profile moves to another machine, a second GPU is removed, or a driver change renumbers the render nodes. Starting a stream or recording then fails with only a generic error in the UI and this in the log:

Failed to create VAAPI device context: Invalid argument

Reproduced with libobs on a Radeon 680M (radeonsi), encoding a color source with ffmpeg_vaapi, ffmpeg_vaapi_tex and hevc_ffmpeg_vaapi:

vaapi_device Result
missing render node (/dev/dri/renderD129) fails, Invalid argument
by-path node of another PCI slot (the issue's path) fails, Invalid argument
primary node the user can't open (/dev/dri/card0) fails, Invalid argument
/dev/null fails, Generic error in an external library
empty string fails, Input/output error or Invalid argument (FFmpeg reads "" as an X11 display or device name, so the report's "leave it empty to auto-detect" doesn't hold)
unset, or the real render node works, 60 frames

Proposed fix and failing test

Fix: if the configured device is set and can encode the codec, use it. Otherwise use the codec's default device and log Device '<configured>' is not usable, falling back to '<default>'. With no usable device, keep the configured path and fail as before. Cost: one extra libva initialisation when an encoder starts.

RED test (cmocka, test_vaapi_device_select), with the choice moved into obs-ffmpeg/vaapi-device-select.[ch] (no libva or FFmpeg calls; the usability probe is a callback): 5 of 7 fail today (missing node, other machine's by-path node, unusable existing node, unusable candidates skipped, empty setting). The 2 that pass pin that a working configured device is kept and that nothing usable still fails as before. With the fix, all 7 pass, and on the 680M all three encoders encode 60 frames for every bad path above.

Activity

  1. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_vaapi_device_select (5 of 7 failing), device choice moved into vaapi-device-select.[ch] with no behaviour change.
    2. GREEN: fall back to the codec's default device when the saved one is unusable, and log it.
    3. Checked on a Radeon 680M with the real encoders.
      PR within the hour.
  2. added a commit that references this issue on Oct 11, 2026
    5fccaf3
  3. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    @chengjilai you reported this in obsproject/obs-studio#13773, so a heads-up: it's fixed here in obs-rust by #198.

    The VAAPI encoders now keep the saved device if it works, and otherwise fall back to the codec's default device (the first render node that encodes it), logging Device '<saved>' is not usable, falling back to '<default>'.

    One correction to the upstream report: leaving the device setting empty doesn't make FFmpeg auto-detect. OBS passes "", which libavutil reads as an X11 display or device name, so it fails too. Workaround on stock OBS: pick the current render node (e.g. /dev/dri/renderD128) in the encoder settings again, or reset the encoder settings so the key is unset.

    obs-rust is an AI-assisted fork of OBS; on Arch it's obs-studio-rust-git in the AUR.

    If you get a chance to try it, a short reply here on whether it fixes it for you would really help, especially if it does not. Your GPU, distro and the device path you had saved are the useful details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions