Skip to content

Progressive H.264 MP4 without CTTS judders on the native path #409

Closed

Description

@orut34iop

What happened?

On a progressive H.264 MP4 VOD with reordered pictures but no composition-time table, the native stream-copy path produces continuous forward/backward judder from the first frame. Seeking is not required to trigger it. The same source plays smoothly in another FFmpeg-based player.

The container presents every sampled video packet with PTS == DTS even though codecpar.video_delay == 1. A bounded libavcodec decode of the same head sample shows the contradiction directly: raw decoded AVFrame.pts regresses 16 times while best_effort_timestamp advances 58 times with zero regressions. Because the PTS values are present rather than AV_NOPTS_VALUE, the existing +genpts open flag and the #407 fallback do not repair them. Stream-copying those packet timestamps into fMP4 preserves decode order as presentation order, so AVPlayer displays future reference pictures before the B pictures that precede them.

Routing only this confirmed shape through the software decoder and scheduling decoded frames on best_effort_timestamp removes the judder.

Steps to reproduce

  1. Open a seekable MP4 containing progressive H.264 with B-frame reordering, but whose sample table has no ctts composition offsets.
  2. Play through the normal native VOD path.
  3. Observe continuous small forward/backward motion from playback start.
  4. Inspect the first 64 video packets and decoded frames. The reporting source produced: valid_pairs=64, PTS==DTS for all pairs, nonkey=62, decoded=59, best_effort_advances=58, best_effort_regressions=0, raw_pts_regressions=16.

A tiny 96x64 H.264 Main, 30000/1001 fps, 3-B-frame synthetic fixture and its healthy ctts twin are ready for a regression test in the accompanying PR.

AetherEngine version or commit SHA

6.39.0 / f70d4aee595f0947ef2354fbae01c76b41a7857b

Host app

Custom integration

Platform

tvOS

OS version

tvOS 26.6 beta (23L773)

Device / chip

Apple TV 4K (3rd generation)

Playback path

Native AVPlayer

Source media (for playback bugs)

MP4 / progressive H.264 with B-frame reordering / SDR. The source has no usable composition offsets: sampled packet PTS and DTS are equal despite video_delay=1. Audio is not involved in the failure. The synthetic regression fixture is MP4 / H.264 Main / 96x64 / 30000/1001 fps / no audio / SDR.

Error codes / log lines

No AVPlayer or VideoToolbox error is emitted. The diagnostic signature is:

video_packets=64 valid_pairs=64 nonkey=62 decoded_frames=59
best_advances=58 best_regressions=0 raw_regressions=16
raw_best_differences=16

Anything else

This is adjacent to #407 but not the same case. #407 repairs only AVFrame.pts == AV_NOPTS_VALUE; here the raw PTS is always present, but it is the wrong decode-order axis. A focused engine patch with bounded fail-closed detection, automatic per-session software routing, and good/bad MP4 fixtures is being prepared.

Activity

  1. superuser404notfound commented on Aug 24, 2026

    @superuser404notfound
    Owner

    Confirmed, and thanks for a report that came with the asset to prove it. The twin fixtures from #411 are now the regression test.

    I reproduced the failure on the Apple decoder rather than only in libavcodec, decoding both twins through AVAssetReader and matching each decoded frame's content against the healthy twin: with ctts removed, 45 of 66 pictures are presented at a time that belongs to a different picture, and the content order steps backwards 30 times, in a repeating +67 ms / -100 ms shuffle per B-group. That is the judder, and no seek is needed to provoke it, exactly as reported.

    The fix is #413, and it takes a different route than routing the session to software decode.

    The container lost the composition offsets, but the bitstream did not: every slice header carries a picture order count, which is display order. libavcodec's H.264 parser reads it without decoding a pixel, and it takes MP4's length-prefixed AVCC payload directly, so the repair costs one slice header parse per video packet. The demuxer then rewrites each packet to what the muxer should have written:

    PTS = (decode time of the picture that opened this coded video sequence) + shift + rank * step
    DTS = DTS + shift - reorderDelay * step
    

    Pulling the decode time back by the reorder delay is what keeps PTS >= DTS, and a healthy file carries the same negative head. The shift is 0 or one reorder delay depending on whether the writer left the sample ladder on the presentation axis or kept the edit list that trims the reorder head, read from the container and clamped to that range, so both writer shapes land on the same axis.

    Because the rewrite happens once at the demuxer boundary, the fMP4 producer, the segment plan, the software decoder and the still extractor all read one axis, and the source keeps the native path with hardware decode: a missing table no longer costs a route change.

    Measurements on the branch:

    • 432 packets across three fixture pairs (both edit-list shapes, seven IDR boundaries): every repaired packet matches its healthy twin's PTS and DTS exactly.
    • served loopback output: all 301 frames present at the same times the healthy twin's output does, 0 mismatches, 0 backward steps.
    • segverify 3/3 segments independently decodable, and a 13-seek burst lands identically on both arms, which is what exercises the re-anchoring after a jump.
    • healthy files stay untouched: the sample leaves on the first real PTS/DTS offset, usually the first packet.

    Detection is fail-closed: a source is only repaired when every sampled pair is equal, the decode ladder is uniform, the picture order regresses, and the ranks it produces are distinct and fill the sampled window. Variable frame timing without composition offsets, a picture order that does not advance one rank per picture, or a sample that cannot be anchored all leave the stream exactly as the container delivered it.

    Leaving this open for a retest on the reporting asset once it ships in a release.

  2. superuser404notfound commented on Aug 24, 2026

    @superuser404notfound
    Owner

    Merged as f08db21. It is on main now, not in a release yet, so this stays open until it can be retested on the reporting asset.

    Two things worth naming from the verification pass, since both would have shipped silently:

    • The segment plan is built from the container's index entries and then filled with these packets, so moving the decode timestamps without moving the index cut one segment past its keyframe. The index is now folded onto the same ladder.
    • The verdict has to be settled while the demuxer still stands at the head. Taken later it lands wherever the cue prewarm left the source, which handed the producer a head six seconds into the file.

    The picture-order parser is also dropped at a seek now, the way libavformat drops its own stream parser (ff_read_frame_flush). Landing on an IDR hides that, because the parser resets its state there, but an open-GOP entry point does not.

  3. added a commit that references this issue on Aug 24, 2026
  4. superuser404notfound commented on Aug 24, 2026

    @superuser404notfound
    Owner

    Released in 6.41.0. Your fixture pair is in the regression suite, and the release notes carry the twin-pair measurement in full, including why best_effort_timestamp could not be the axis. Leaving this open for your retest on the original file.

  5. orut34iop commented on Aug 25, 2026

    @orut34iop
    ContributorAuthor

    Retested the released #413 + #415 implementation on the original reporting asset: playback still judders continuously from the first frame without seeking. This is not the held-packet seek regression fixed by #415.

    The sampled head has PTS == DTS for 12/12 packets, video_delay=1, time_base=1/1200000, and the repeating DTS-step cycle 40040,40041,40040,40040,40041. Current main requires one identical integer step, so it fails closed as a nonuniform decode ladder and repairs 0 packets.

    The exact observed cadence is 200202/5; this is not generic VFR support. The follow-up accepts only a repeated adjacent-integer cycle observed for at least two periods, corroborated by stream rate metadata, with a unique quantization phase and a complete safe dry-run. Ambiguous, malformed, and genuinely variable timing remains untouched.

    The patched candidate has now passed physical Apple TV verification on the original asset: direct playback is smooth, scrub/release resumes and remains smooth, and a separate unaffected video remains unchanged.

    Proposed engine patch and regression coverage: #419

  6. added 2 commits that reference this issue on Aug 25, 2026
  7. 4 remaining items

  8. superuser404notfound commented on Sep 3, 2026

    @superuser404notfound
    Owner

    Released in 6.44.0 (69daa3d3), the same evening as the comment above, and this thread never got the note. So the retest on the original asset has had a pin to sit on since then. The two numbers worth reporting back are unchanged: the cadence= in the #409 ... confirmed line, and whether any picture comes out unrepaired.

  9. orut34iop commented on Sep 13, 2026

    @orut34iop
    ContributorAuthor

    Thanks for the fix and the release follow-up. The original reporting MP4 is no longer available to us, so we cannot complete the requested retest of the released #427 implementation on that asset or provide its cadence= verdict and evidence of whether any pictures remain unrepaired.

    Our integration has since been updated to AetherEngine 6.84.0, but testing other files does not establish that the original asset is fixed. Please treat original-asset validation as unavailable, rather than passed.

    Thank you for preserving the synthetic twin fixtures and the regression coverage. We leave the issue's closure to your judgment based on the available evidence.

  10. superuser404notfound commented on Sep 13, 2026

    @superuser404notfound
    Owner

    Thank you for saying that plainly instead of passing it on a substitute file. "Unavailable" is the more useful of the two answers, and it goes in the record that way.

    So the thread ends with its evidence named rather than with a verdict it never got, here is what the shipped repair actually stands on:

    • The shape you measured is in the suite as ground truth, not as a guess about it. The twin pair was built to that cadence: 33 pictures at 1000000/33367 fps in a 1200000 timescale, so a picture is 200202/5 ticks long and the sample table can only alternate 40040/40041, with the composition offsets stream-copied away from the second file the way your original pair was made.
    • On that pair every repaired packet carries the healthy twin's PTS and DTS exactly, 33 of 33, the presentation axis is a bijection with no backward step, and the healthy twin leaves the demuxer as the container wrote it.
    • The verdict no longer depends on where the sample was taken, so a session that starts after a seek reads the same axis as one that starts at the head. That was the second defect the phase reading turned up, and it has its own test.

    What that does not cover, and I am not going to claim it does: the original file, end to end, on a device, with the released implementation. The nearest thing to it stays your own measurement in this thread, on that asset, on physical hardware, of the same diagnosis. #427 implements that diagnosis with a per-sequence anchor rather than a per-packet inversion, which is the more conservative of the two: a sequence the lattice cannot place falls back to the rounded step at the container's own timestamp and is never handed on in decode order.

    Re-checked today against 6.84.0, the version your integration now runs: the H264CompositionOffsetRepair suite is green, 31 tests, the fractional pair included.

    Closing on that basis, with original-asset validation recorded as unavailable rather than passed. If this judder ever turns up again, on that file or another, the line worth quoting is the one the demuxer prints at the head:

    [Demuxer] #409 missing H.264 composition offsets confirmed on stream 0: repair step=… lead=… shift=… pocStep=… cadence=… phase=… ladderAhead=… samples=…
    

    or its counterpart, #409 composition-offset probe on stream 0 left the stream untouched: <reason>, which names what the classifier refused on. One shape that is deliberately not this one: a file carrying valid offsets at the head and zeros later reads as healthy here, and that is #513.

    Thanks again for the fixtures, the measurements and the two rounds of diagnosis. The pair you supplied is what the regression rests on.

  11. added a commit that references this issue on Oct 7, 2026
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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions