Skip to content

Fall back to SPS frame_mbs_only_flag when demuxer field_order is UNKNOWN (#150) - #155

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/ae150-sps-interlaced-routing-fallback
Jul 19, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/ae150-sps-interlaced-routing-fallback

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Fixes #150.

Problem

Some interlaced live H.264 channels are interlaced at the SPS level (frame_mbs_only_flag=0) but the demuxer's field-order probe returns UNKNOWN instead of TT/BB/TB/BT. The #107 routing rule only consults field_order, so these channels stayed on native VideoToolbox decode, which does not deinterlace, producing a persistent green colour cast from the first frame.

Fix

  • H264SPS: expose frameMbsOnly(fromNAL:) (the parser already walked the flag for dimensions) and spsNAL(fromExtradata:), which accepts both extradata layouts, Annex-B (MPEG-TS) and avcC (MP4/MKV).
  • VideoRoutingPolicy.requiresSoftwarePath gains spsIndicatesInterlaced, consulted only when field_order is UNKNOWN. A concrete PROGRESSIVE probe (which analyzed actual frames) still wins over the SPS capability flag. New pure helper spsIndicatesInterlaced(extradata:) classifies extradata.
  • AetherEngine.load computes the fallback from codecpar extradata and logs fieldOrder=UNKNOWN but SPS frame_mbs_only_flag=0; treating as interlaced for routing (#150) when it fires.

Safety: a false positive (interlaced-capable SPS carrying progressive frames) only pays an unnecessary software decode. The SW decoder gates bwdif per frame on AV_FRAME_FLAG_INTERLACED from the slice headers, so progressive frames pass through untouched. Unparseable or missing extradata classifies as not-interlaced and keeps the native path.

Tests

  • Interlaced Main-profile 1920x1080 SPS fixture (frame_mbs_only=0, PAFF, the reporter's channel shape), validated against the existing dimensions parser.
  • frameMbsOnly true/false/nil cases, SPS extraction from Annex-B and avcC extradata, garbage rejection.
  • Routing matrix: UNKNOWN+SPS-interlaced routes software, UNKNOWN without signal stays native (unchanged default), PROGRESSIVE wins over SPS, concrete field orders and non-H.264 codecs ignore the new parameter.
  • Full suite: 762 tests in 129 suites green, strict-concurrency=complete build clean, tvOS Simulator build green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NAPCg4tCDdSqkK6tPkNptw

… UNKNOWN (#150)

Some interlaced live H.264 channels (frame_mbs_only_flag=0 in the SPS) probe
with field_order=UNKNOWN, silently defeating the #107 interlaced-goes-software
rule and leaving them on native VideoToolbox decode with a persistent colour
cast. When the field-order probe is inconclusive, parse the SPS from codecpar
extradata (Annex-B and avcC layouts) and treat frame_mbs_only_flag=0 as
interlaced for routing. A concrete PROGRESSIVE probe still wins, and a false
positive only costs an unnecessary software decode since deint passes
progressive frames through untouched.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NAPCg4tCDdSqkK6tPkNptw
@superuser404notfound
superuser404notfound merged commit 04cea7d into main Jul 19, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/ae150-sps-interlaced-routing-fallback branch July 19, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interlaced live H.264 with unknown demuxer field_order stays on native decode (AVPlayer/VideoToolbox), produces persistent green colour cast

1 participant