Skip to content

obs-ffmpeg: Fall back to CPU VAAPI without GPU textures - #207

Merged
zackees merged 3 commits into
obs-rust:masterfrom
rdoupe:fix/206-texture-encoder-raw-format
Oct 11, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
rdoupe:fix/206-texture-encoder-raw-format

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Description

Starting a recording or stream crashed OBS when a VAAPI texture encoder (ffmpeg_vaapi_tex, hevc_ffmpeg_vaapi_tex) was selected and the Color Format was anything other than NV12 or P010 (I444, I420, BGRA, ...). With this change the VAAPI texture encoders fall back to their CPU-side VAAPI encoder in that case, and libobs refuses any texture-only encoder that can't get textures with a clear error instead of crashing.

The cause: gpu_encode_available() (libobs/obs-encoder.c:219) is only true when the video mix produces NV12/P010 textures. Otherwise the encoder is connected to raw frames, and do_encode() (obs-encoder.c:1483) calls info.encode, which texture-only encoders leave NULL. NVENC and QSV avoid this by rerouting to their CPU encoder from create(); the VAAPI texture encoder didn't.

  1. test/cmocka: Add RED texture-only encoder on raw video test: registers a fake texture-only encoder (encode = NULL, encode_texture2 set, OBS_ENCODER_CAP_PASS_TEXTURE) and a fake encoded output on a video output with no GPU textures, each case in a forked child. 4 of 5 fail on this commit (the child crashes with signal 11): tex_only_i444_refused, tex_only_i420_refused, tex_only_bgra_refused, tex_only_nv12_without_textures_refused. The control, hybrid_i444_starts (an encoder with a CPU encode), passes. The test provides obs_get_video_info() itself (as test_formatted_filename.c does), because the bare video output has no core video mix; it needs a display for obs_startup and skips without one, like test_audio_io, and skips on Windows and macOS.
  2. libobs: Refuse texture-only encoders without GPU textures: in obs_encoder_initialize_internal(), after create() (so an encoder that rerouted already has its encode), a video encoder with no encode callback and no GPU textures is shut down and given a last error: "The selected encoder can only encode GPU textures, which are not available for the I444 color format. Use the NV12 or P010 color format, or a different encoder." The output copies it and refuses to start. This also covers third-party texture-only encoders that don't reroute.
  3. obs-ffmpeg: Fall back to CPU VAAPI without GPU textures: vaapi_create_tex_internal() reroutes to ffmpeg_vaapi / hevc_ffmpeg_vaapi / av1_ffmpeg_vaapi when NV12/P010 textures aren't active, like NVENC and QSV. All 5 tests pass.

Motivation and Context

Fixes #206 (upstream obsproject/obs-studio#12731, reported by tomben13)

Why this one: it's a hard crash from an ordinary settings combination (I444 is a common choice for higher-quality recording), with no upstream fix, and VAAPI is the hardware encoder most Linux users with AMD or Intel GPUs have.

How Has This Been Tested?

Automated: test_texture_encoder_raw_format fails 4 of 5 at the RED commit and passes 5 of 5 at the GREEN commit, in 5 runs each after clean rebuilds, on two machines (Ryzen with Radeon 680M, and Ryzen AI with Radeon 860M) under a private Xvfb. clang-format is clean.

By hand, headless on a Radeon 680M (radeonsi, Mesa 26.2), recording to MP4 through a private headless compositor with the GL renderer:

Color format before after
NV12 records records (texture encoder)
I444 segfault in do_encode (0x0), matching the report's backtrace records ("falling back to ffmpeg_vaapi encoder"; valid h264)
I420 segfault records
BGRA segfault records

Both ffmpeg_vaapi_tex and hevc_ffmpeg_vaapi_tex were checked. With only the libobs commit (VAAPI change removed), I444 and BGRA fail to start cleanly with the error above instead of crashing.

Not tested:

  • Intel VAAPI, and AV1 VAAPI.
  • Third-party texture-only encoders (covered by the libobs check, not run).
  • The Rust and Docker lanes of the local gate.

Separately noticed, not changed here: calculate_batch_size() (libobs/obs-output.c:2713) ignores obs_get_video_info()'s return and reads an uninitialised obs_video_info when there is no core video mix. The OBS app always has one, so users can't hit it; embedders could.

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

rdoupe and others added 2 commits October 11, 2026 02:06
Starting an output with a texture-only video encoder (encode == NULL,
encode_texture2 set) while the video mix produces no NV12/P010 textures
connects the encoder to raw frames, and do_encode() calls the missing
info.encode through a NULL pointer on the video thread. Reported upstream
in obsproject/obs-studio#12731 by tomben13 with ffmpeg_vaapi_tex and an
I444 color format.

The test registers a fake texture-only encoder and a fake encoded output,
starts the output on a bare I444/I420/BGRA/NV12 video_t (no core video
mix, so no GPU needed) and expects the start to be refused with an error.
A control encoder with a CPU encode callback must still start and encode.
Each scenario runs in a forked child so the crash fails the test.

Refs obs-rust#206.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A video encoder without a CPU encode callback can only run when libobs
feeds it NV12/P010 textures. When the video mix does not produce them
(e.g. the I444, I420 or BGRA color formats), add_connection() connects the
encoder to raw frames and do_encode() calls the NULL encode on the video
thread, crashing OBS as soon as recording starts.

Texture encoders are expected to reroute to their CPU sibling from
create() in that case, as obs-nvenc and obs-qsv11 do. If one did not,
fail encoder initialization with a last error naming the color format so
the output refuses to start instead of crashing.

Reported upstream in obsproject/obs-studio#12731 by tomben13.

Refs obs-rust#206.

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 06:07
The VAAPI texture encoders did not check whether the video mix produces
NV12/P010 textures before creating themselves, so with any other color
format they were attached to raw frames they cannot encode. Reroute to
the matching non-texture VAAPI encoder in that case, as obs-nvenc and
obs-qsv11 already do, so recording works with the CPU upload path.

Reported upstream in obsproject/obs-studio#12731 by tomben13.

Fixes obs-rust#206.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=4bc4294df7845153d643ab98afa116ddf34d28bd secs=83 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791699391,"gate":"rust/all/fmt","host":"linux-x86_64","key":"a0551e66800458b91188cbc7e0603f8086d7d68f27d0914cab4c27907c9c384a","lane":"lint","parents":["130b7d1628cf16a689a1bb139e6d0cae33c7da60"],"secs":15,"stamp":"a2ea098357bcabbe3db276bec4b3ab9d","tree":"4bc4294df7845153d643ab98afa116ddf34d28bd","v":1,"via":"run"}
Ci-Attestation: {"at":1791699391,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"a0551e66800458b91188cbc7e0603f8086d7d68f27d0914cab4c27907c9c384a","lane":"lint","parents":["130b7d1628cf16a689a1bb139e6d0cae33c7da60"],"secs":15,"stamp":"029af5ba5f05bfeb5d87d17206c3254f","tree":"4bc4294df7845153d643ab98afa116ddf34d28bd","v":1,"via":"run"}
Ci-Attestation: {"at":1791699391,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"f63b0760be62be43b0461f5a52646b6d9055ae79fefdd3b377a2935013b204a3","lane":"rust-test","parents":["130b7d1628cf16a689a1bb139e6d0cae33c7da60"],"secs":30,"stamp":"84d6f62ee811159a183990500c87b67b","tree":"4bc4294df7845153d643ab98afa116ddf34d28bd","v":1,"via":"run"}
Ci-Attestation: {"at":1791699391,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"14cc0a7155d4e20e31e3cb5ccb30448815b5c59ca100e4e7b1877a3b7583fb4a","lane":"tier2-linux","parents":["130b7d1628cf16a689a1bb139e6d0cae33c7da60"],"secs":38,"stamp":"a16a29f4b993c4a649be0b578b5ffa27","tree":"4bc4294df7845153d643ab98afa116ddf34d28bd","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 5535dd721.

test_texture_encoder_raw_format skips without a display, and the Tier 2 container (like CI) has none. Plain Tier 2 therefore reports it as passed even on the RED commit. I ran it under xvfb-run, on the Tier 2 build of each commit:

  • RED 3fbef0920: 1 of 5 passed. tex_only_i444_refused, tex_only_i420_refused, tex_only_bgra_refused and tex_only_nv12_without_textures_refused failed, and NV12 crashed with signal 11.
  • 130b7d162 (libobs refusal): 5 of 5 passed. The log shows Encoder 'venc' (test_tex_only_encoder) can only encode GPU textures, which are not available for video format I420.
  • 4a10a020d (VAAPI fallback): 5 of 5 passed. Tier 2 passed 65 of 65 with ENABLE_RUST_LIBOBS OFF and 65 of 65 with it ON. Local gate: lint, rust-test and tier2-linux all passed.

Follow-ups, non-blocking:

  1. The test only protects anything where a display exists. Running it under xvfb-run in Tier 2 or CI would make it a real regression guard.
  2. The VAAPI reroute has no test of its own. It mirrors what NVENC and QSV already do.

Merging once CI is green.

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: libobs/obs-ffmpeg: VAAPI texture encoder crashes on non-NV12/P010 color formats (upstream #12731)

2 participants