Skip to content

media: preserve the final picture in regular H.264 transport streams (#778) - #4030

Merged
FredApps merged 3 commits into
storytold:mainfrom
FredApps:fix/778-h264-ts-final-picture
Nov 21, 2026
Merged

FredApps merged 3 commits into
storytold:mainfrom
FredApps:fix/778-h264-ts-final-picture

Conversation

@FredApps

@FredApps FredApps commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of storytold/craft-libs#778 and storytold/craft-libs#781 (scoped claim).

The shared H.264 transport-stream reader reports the last picture's start as the duration, so public playback can clamp a request for that picture to the preceding frame. Include the final display period only for video-only H.264 transport streams with a clean, aligned packet index, a leading random-access picture, and complete readable timestamps at an exact regular cadence. All other inputs retain their previous indexed duration. No codec, seek, audio, dependency, or workflow changes.

The generated regression is intended to compare a two-frame transport stream with the Film reader and verify the final frame through the public probe and media pool. Guard tests cover damaged and partial tails, missing or irregular timing, and unit-size bounds. Diff checks and independent source review completed; builds and these tests have not run. Normal hosted CI is pending.

Summary by CodeRabbit

  • Bug Fixes
    • Playback duration is now estimated more accurately for eligible H.264 transport-stream videos, including the final picture, when timing information is complete and regular.
    • For incomplete, damaged, or irregular video data, duration continues to use the indexed timestamp span rather than an unreliable picture-timing estimate. This avoids extending playback duration when the final picture’s timing cannot be determined reliably.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

MPEG-TS duration now uses a picture-end estimate for eligible single-stream H.264 input with a clean packet index. When the estimate cannot be used, the route retains the indexed PTS span. Tests cover the estimate, final-picture retrieval, and damaged or partial tails.

Changes: MPEG-TS duration

Layer / File(s) Summary
Duration estimation and eligibility
crates/media/src/craft_source.rs
The picture-end estimate checks key-picture origin, readable units, positive constant PTS spacing that matches the frame rate, and arithmetic bounds. A separate check validates TS packet-index conditions.
Route integration and MPEG-TS tests
crates/media/src/craft_source.rs
The duration route uses the estimate only for eligible single-stream H.264 input; otherwise it retains the indexed PTS span. Generated-fixture tests cover final-picture duration and retrieval, damaged or partial tails, and rejected estimate inputs.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Suggested reviewers: dylanmtaylor, terra854

Merge Risk: Minimal · up to ba74b

This change extends the reported duration of regular video-only H.264 transport streams so the last picture can be requested. Other inputs keep their previous duration. No concrete merge-blocking risk was found. Normal CI should confirm the new tests.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the final picture is preserved in regular H.264 transport streams. The raw summary confirms the change adds inferred end-of-final-picture duration for single-stream H.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the final picture is preserved in regular H.264 transport streams. The raw summary confirms the change adds inferred end-of-final-picture duration for single-stream H.264 MPEG-TS files with a clean index, falling back to the indexed span otherwise. The title's '(#778)' suffix differs from the PR objectives' reference to #4030, but that does not affect topical relevance. The title is specific and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.1)

Clippy execution timed out
Clippy (1.99.1) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 421b013 and ba74b98.

Files selected for processing: 1

  • crates/media/src/craft_source.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@FredApps
FredApps marked this pull request as ready for review November 21, 2026 14:41
@FredApps
FredApps merged commit 52c78fd into storytold:main Nov 21, 2026
10 checks passed
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.

2 participants