Skip to content

Fix the output conformance matrix's findings (task #58) - #220

Open
StuartCameronCode wants to merge 7 commits into
mainfrom
stuart/58-output-conformance-matrix-findings-avi-r
Open

StuartCameronCode wants to merge 7 commits into
mainfrom
stuart/58-output-conformance-matrix-findings-avi-r

Conversation

@StuartCameronCode

Copy link
Copy Markdown
Owner

Fixes the five failures task #49's output conformance matrix found. The matrix's knownFailures list is now empty: three full runs passed 450/450.

Changes

  1. Restore + Convert AAC into AVI, trimmed, stored 49 pictures for 50. When an encoder priming applies, a trimmed encode now stops at the window's length (-t, encode_end_args) instead of -shortest. New tail matrix cases trim to the last picture for every primed Convert codec into AVI.
  2. A seeked MP2 restore was not sample-exact. The Audio Restoration render reads MP1/MP2 with FFmpeg's float decoders (render_decoder), which give the same samples from any seek. Convert and the analysis keep FFmpeg's default decoder.
  3. The delayed AVI's clicks were 31 ms late. This was not a worker fault. The source's own MP3 is 23 ms late, from libmp3lame priming that AVI cannot mark. The test now measures each click against the source's own lag, which it measures and bounds.
  4. pipe_source served wrong frames when VapourSynth asked out of order.
    • It now keeps every frame until it has been served, plus the temporal window behind the oldest unserved frame. Memory is capped at 512 MB beyond that window.
    • A frame requested after it was dropped now raises. Before, it silently returned the last frame read.
    • A new push-gate test (pipe_source_order_test.dart) reproduces the order that failed.
  5. An off-grid timestamp reset joined 16 ms late.
    • The picture now sets one offset per segment (JoinPlan), applied with -copyts and a setts filter on each stream.
    • A sound packet that overhangs the next segment is dropped, and the log says so.
    • When no plan can be made, the copy falls back to ffmpeg's own correction. Since review, it also falls back when the planned copy fails its check.

CLAUDE.md, ENGINEERING_NOTES and a new report (docs/reports/task-58-output-conformance-findings/, with its scripts) document the rules. Task #49's report has a correction.

Testing

  • Matrix: integration_output_conformance_test.dart (heavy) passed 450/450 in three full runs. A fourth run was void, and the report explains why.
  • After the review fix: all 37 reset-ps/mid matrix cases and the off-grid join test pass.
  • Rust (cargo test): passes, except subtitle_integration_test, which needs the whisper add-on and couldn't run locally.
    • A new test, a_planned_join_that_fails_falls_back_to_ffmpegs_correction, fails without the fallback.
  • Push gate: the Dart tests pass, including pipe_source_order_test and output_matrix_cases_test.

Known edge cases (not in any fixture)

  • An audio stream that starts only after a reset would not be shifted.
  • Only one overhanging sound packet is dropped per join.
  • An empty declared stream would shift the stream numbering.

🤖 Generated with Claude Code

@StuartCameronCode
StuartCameronCode force-pushed the stuart/58-output-conformance-matrix-findings-avi-r branch from 1031ee7 to 31b5a09 Compare November 17, 2026 12:59
StuartCameronCode and others added 7 commits November 18, 2026 15:01
…e (task #58)

VapourSynth runs the pipe clip's callbacks out of order: vspipe requests a
new frame each time any completes, so one late early frame let the reader
read to the end of the clip past it, and the frame then came back as
whatever was read last. Measured: 6 wrong outputs in 320 plain runs under
load, 0 after.

The reader now keeps every frame until it has been served and is a window
behind the oldest frame not yet served, with a memory cap for frames never
asked for. A frame asked for after it was dropped raises instead of being
replaced by another picture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rs exact; source-relative clicks (task #58)

- Convert into AVI under an encoder priming reads every sound input late
  by P, so a sound ending with the window (the restored track) ended
  before the picture and -shortest dropped the last picture (49 of 50).
  Such a trim now stops at the window's length (-t), encode_end_args.
- Audio Restoration reads MP1/MP2 with the float decoders: the default
  fixed-point decoders round with state carried between frames, so a
  seeked decode differed from the full one by one 16-bit step in ~40% of
  samples. The float decode is exact from any seek.
- The matrix oracle expects each click at the source's own lag after its
  flash: conf_delayed.avi's MP3 is 23 ms late by libmp3lame's priming,
  which AVI can't mark; the copy cut's +8 ms is its nearest-packet rule.
  The restore cases compare against the render's decoder.
- knownFailures is empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… into AVI (task #58)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ask #58)

ffmpeg's discontinuity correction takes one offset per segment from
whichever stream shows the reset first. When a segment's sound runs past
its last picture (16 ms in conf_reset_offgrid.mpg, as a DVD cell's may),
that is the sound, so every later picture landed off the grid: one 56 ms
step, ffprobe read 125 fps and the app analysed 493 pictures for 100.

The scan now also reads each packet's duration and position and makes a
JoinPlan: each segment moves so its first picture follows the last by one
frame, every stream of the segment alike. The copy runs with -copyts and a
setts bitstream filter per stream (by packet index for streams that reset,
by byte position for those that don't: subtitles); a sound packet that
overhangs the next segment by more than half of itself is dropped (noise)
and the log says so. Without a plan (no durations, streams resetting a
different number of times) the copy is exactly as before.

On conf_reset.mpg (on the grid) the copy times every picture and sound
frame as ffmpeg's join did; on the off-grid fixture picture 50 is at
2.000 s (was 2.016), 25 fps, 100 pictures. The off-grid matrix test is an
ordinary test now, and av_sync.events times an untimed picture one step
after the last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… in task #49's report

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… run's cause

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s correction (task #58 review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@StuartCameronCode
StuartCameronCode force-pushed the stuart/58-output-conformance-matrix-findings-avi-r branch from 31b5a09 to 8e7be1a Compare November 18, 2026 04:01
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.

1 participant