Skip to content

feat(timing): SPS VUI frame rate and VFR-aware seeking - #62

Merged
blocksmith314 merged 1 commit into
mainfrom
feature/vui-fps-vfr
Nov 13, 2026
Merged

blocksmith314 merged 1 commit into
mainfrom
feature/vui-fps-vfr

Conversation

@blocksmith314

Copy link
Copy Markdown
Owner

Summary

Fixes #10.

VUI frame rate for raw streams

MainWindow now overrides the decoder's guessed frame rate for raw Annex B streams with the SPS VUI timing:

  • H.264: time_scale / (2 * num_units_in_tick)
  • H.265: vui_time_scale / vui_num_units_in_tick

This affects playback pacing, the Time display mode and audio sync.

VFR-aware seeking

FFmpegDecoder::BuildFramePts() performs one demux-only pass over container packets and records each packet PTS in seconds (decode order). SeekByContainer() uses frame_pts[target_index] instead of the index / fps estimate, then falls back to the old formula if the table is missing or too short.

Trade-offs:

  • first container seek pays one full demux pass (no decoding); it is cached until the file is reopened
  • assumes one packet per frame, which holds for typical MP4/MKV; a future improvement is to parse stts/ctts in mp4index

Tests

  • H264ParamsTest.ParsesVuiFrameRate
  • ctest: 69/69 pass
  • tidy.sh on the touched files: 0 issues

Fixes #10

- for raw Annex B streams override FFmpeg's guessed frame rate with the
  SPS VUI timing (H.264 time_scale/(2*num_units_in_tick), H.265
  time_scale/num_units_in_tick)
- build a per-frame PTS table from container packets on the first seek and
  use it for SeekByContainer, so variable-frame-rate content lands on the
  requested frame instead of an index/fps estimate
- fall back to the previous estimate when the table is unavailable
- add a VUI frame-rate parsing test

Fixes #10
@blocksmith314
blocksmith314 merged commit 34c5a98 into main Nov 13, 2026
3 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.

Timing: use SPS VUI frame rate for raw streams and real PTS for VFR seeking

1 participant