Skip to content

libobs: Fix Yadif 2x field order for bottom field first - #317

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/6061-yadif-2x-field-order
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/6061-yadif-2x-field-order

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Description

Yadif 2x deinterlacing of bottom-field-first video now shows the fields in capture order instead of jumping back and forth.

In deinterlace_base.effect, load_at() picks the frame by row parity only (even rows from the current frame, odd rows from the previous one), and texel_at_yadif_2x() keeps rows of parity field_order on the first pass and the other parity on the second (field_order is 1 for top field first, 0 for bottom field first, obs-source-deinterlace.c). For top field first that shows the previous frame's bottom field and then the current frame's top field, which is in order; for bottom field first it showed the current frame's top field and then the previous frame's bottom field, so every other output frame went back three fields in time. Upstream 84ce107 (2016) flipped the linear and discard 2x modes and kept yadif 2x as "correct due to how it operates", which only holds for top field first.

  1. test: Check double-rate deinterlacing keeps fields in capture order: test_deinterlace_2x_field_order registers an async BGRA source that outputs 36 interlaced frames at 30 fps into a 60 fps canvas, with each field's rows carrying its capture index and parity, and classifies every output frame (obs_add_raw_video_callback) by the field it kept. It asserts the shown fields never go back in time and that at least 36 fields appear, for Yadif 2x, Linear 2x and Discard 2x, each top and bottom field first. Today only Yadif 2x bottom field first fails: 1 3 0 5 2 7 4 9 6 ..., 35 steps back in 71 fields.
  2. libobs: Fix Yadif 2x field order for bottom field first: one line in the form of rob-fi's workaround from the upstream thread — the first field of a frame now comes from the current frame and the second from the previous one, so the kept field always sits between the two frames it is interpolated from. Top field first output is mathematically unchanged. All 6 cases pass (1 2 3 4 ...).

Side effect: single-rate Yadif with bottom field first now keeps the previous frame's top field rather than the current one, matching what top field first already did (one field of latency, correct yadif bracketing).

Motivation and Context

Fixes #316 (upstream obsproject/obs-studio#6061, reported by ray890; also faradey8951 and rob-fi)

Why this one: Yadif 2x is the recommended deinterlacer, and with bottom-field-first sources (DV and many capture devices) it visibly judders; open since 2022 with users' own shader patches. No upstream fix exists.

How Has This Been Tested?

Automated, in both libobs lanes (ENABLE_RUST_LIBOBS OFF and ON), rebased on current master:

  • test_deinterlace_2x_field_order: 1 of 6 fails at the RED commit (Yadif 2x BFF), 6 of 6 pass at GREEN (5 repeated runs).
  • Full ctest at GREEN: 100 of 100 in each lane under a private Xvfb; without a display the new test's cases skip, like the other core tests.
  • clang-format, gersemi and ci/test_registration.py are clean; the test is registered for Linux only, with its working directory inside that guard.

Not tested: Blend 2x (its shader ignores field_order; possibly a separate bug), single-rate Yadif with BFF, real interlaced media, GPU-converted async formats (NV12/I420), and the D3D11 and Metal backends (the change is a plain integer comparison in the shared effect; only OpenGL/llvmpipe was run).

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
rdoupe requested a review from zackees as a code owner October 12, 2026 05:00
rdoupe and others added 2 commits October 11, 2026 22:12
A test async source outputs interlaced BGRA frames at 30 fps into a 60 fps
canvas. Every field carries its capture index in its rows and its parity in
green, so each output frame can be classified by the field it kept. The
fields shown must never go back in time, for Yadif 2x, Linear 2x and
Discard 2x (Retro), top and bottom field first.

On master Yadif 2x with bottom field first shows the fields as
1 3 0 5 2 7 4 9 6 ... (35 steps back in time over 36 frames), while top
field first and the Linear 2x and Discard 2x cases are in order.

Reported upstream in obsproject/obs-studio#6061 by ray890.

Refs obs-rust#316.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Yadif keeps one field and interpolates the other from the previous and
current frames. load_at() picked the frame by row parity alone: top rows
from the current frame, bottom rows from the previous one. That is right
for top field first, where the 2x pass shows the previous frame's bottom
field and then the current frame's top field. For bottom field first it
shows the current frame's top field and then the previous frame's bottom
field, so every other output frame went back three fields in time
(1 3 0 5 2 7 4 ...), and the kept field was not between the two frames
it was interpolated from.

Take the first field of a frame (the parity opposite field_order) from
the current frame and the second from the previous one. Top field first
output is unchanged; bottom field first now shows 1 2 3 4 ... like top
field first, also with single-rate Yadif keeping the field between its
neighbours. rob-fi found this condition while testing on DV footage in
the upstream issue.

Fixes obs-rust#316.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=dd2d92fb3593d4f6e85152bd669a590c6abd405d secs=116 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791782082,"gate":"rust/all/fmt","host":"linux-x86_64","key":"ed7f2cdfee5b155a7f9f37a67a15f779ce6c81312e2b31af7d38cce8a9928569","lane":"lint","parents":["a52bee134a202a877decfbf16d80192e0d6e6c8c"],"secs":16,"stamp":"a9c18a3452b68a735f1668ac173c72d3","tree":"dd2d92fb3593d4f6e85152bd669a590c6abd405d","v":1,"via":"run"}
Ci-Attestation: {"at":1791782082,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"ed7f2cdfee5b155a7f9f37a67a15f779ce6c81312e2b31af7d38cce8a9928569","lane":"lint","parents":["a52bee134a202a877decfbf16d80192e0d6e6c8c"],"secs":16,"stamp":"781597a0cbe580e2eb8d71e9e02dc92e","tree":"dd2d92fb3593d4f6e85152bd669a590c6abd405d","v":1,"via":"run"}
Ci-Attestation: {"at":1791782082,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"ea9e096a176bf244ead39c5f119d69f4c58c329cf3b1d8da651ce3f052e412c6","lane":"rust-test","parents":["a52bee134a202a877decfbf16d80192e0d6e6c8c"],"secs":46,"stamp":"8cedae9ccc6b9163759e735f0e883a2a","tree":"dd2d92fb3593d4f6e85152bd669a590c6abd405d","v":1,"via":"run"}
Ci-Attestation: {"at":1791782083,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"4db66a04d528e856ae47878c87435d449fbd2b7f1416eae9f3c795862a012f26","lane":"tier2-linux","parents":["a52bee134a202a877decfbf16d80192e0d6e6c8c"],"secs":54,"stamp":"743c39309cfa72c7de48b64824448969","tree":"dd2d92fb3593d4f6e85152bd669a590c6abd405d","v":1,"via":"run"}
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

Verified locally on master. The test renders through libobs-opengl, so I ran it with xvfb-run ctest plus Mesa llvmpipe on each commit's Tier 2 build:

  • RED (d8378f2cc): 5 of 6 passed. yadif_2x_bottom_first failed (the other field-order and mode cases are unchanged, as they should be).
  • GREEN (715344f18): 6 of 6 passed. Plain Tier 2 passed 101 of 101 with ENABLE_RUST_LIBOBS OFF and 101 of 101 with it ON, and the local gate passed.

Merging once CI is green.

@zackees
zackees force-pushed the fix/6061-yadif-2x-field-order branch from 715344f to a316e42 Compare October 12, 2026 05:14
@zackees
zackees merged commit ee4cc0a into obs-rust:master Oct 12, 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: libobs: Yadif 2x shows bottom-field-first video out of order (upstream #6061)

2 participants