Repository navigation
obs-ffmpeg: Fall back to CPU VAAPI without GPU textures - #207
Merged
zackees merged 3 commits intoOct 11, 2026
Merged
Conversation
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]>
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"}
Member
|
Verified locally, rebased onto master and stamped. The new head is
Follow-ups, non-blocking:
Merging once CI is green. |
zackees
force-pushed
the
fix/206-texture-encoder-raw-format
branch
from
October 11, 2026 06:16
4a10a02 to
5535dd7
Compare
This was referenced Oct 11, 2026
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
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, anddo_encode()(obs-encoder.c:1483) callsinfo.encode, which texture-only encoders leave NULL. NVENC and QSV avoid this by rerouting to their CPU encoder fromcreate(); the VAAPI texture encoder didn't.test/cmocka: Add RED texture-only encoder on raw video test: registers a fake texture-only encoder (encode= NULL,encode_texture2set,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 CPUencode), passes. The test providesobs_get_video_info()itself (astest_formatted_filename.cdoes), because the bare video output has no core video mix; it needs a display forobs_startupand skips without one, liketest_audio_io, and skips on Windows and macOS.libobs: Refuse texture-only encoders without GPU textures: inobs_encoder_initialize_internal(), aftercreate()(so an encoder that rerouted already has itsencode), a video encoder with noencodecallback 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.obs-ffmpeg: Fall back to CPU VAAPI without GPU textures:vaapi_create_tex_internal()reroutes toffmpeg_vaapi/hevc_ffmpeg_vaapi/av1_ffmpeg_vaapiwhen 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_formatfails 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:
do_encode(0x0), matching the report's backtraceBoth
ffmpeg_vaapi_texandhevc_ffmpeg_vaapi_texwere 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:
Separately noticed, not changed here:
calculate_batch_size()(libobs/obs-output.c:2713) ignoresobs_get_video_info()'s return and reads an uninitialisedobs_video_infowhen there is no core video mix. The OBS app always has one, so users can't hit it; embedders could.Types of changes
Checklist:
🤖 Generated with Claude Code