Skip to content

Fix missing initial frames and seeking in MPEG-TS/M2TS files - #1108

Open
rajeshgk wants to merge 1 commit into
OpenShot:developfrom
rajeshgk:fix/mpegts-pts-offset
Open

rajeshgk wants to merge 1 commit into
OpenShot:developfrom
rajeshgk:fix/mpegts-pts-offset

Conversation

@rajeshgk

Copy link
Copy Markdown

Summary

Fix frame-accurate reading and seeking of MPEG-TS/M2TS (AVCHD) video files in FFmpegReader.

Addresses #1031.

Problem

When importing MPEG-TS/M2TS files into OpenShot, the first 25–30 frames can be missing or delayed during clip and timeline preview.

Remuxing the same video to MP4 without re-encoding avoids the issue, indicating a container-specific timestamp and seeking problem.

Changes

  • Correct the frame-to-video-PTS conversion to account for the initial timestamp offset.
  • Correct working-frame timestamp alignment.
  • Index MPEG-TS video keyframes while reading packets.
  • Use indexed byte positions for MPEG-TS seeking when a suitable keyframe is available.
  • Preserve the keyframe index across internal reader reopens.
  • Reset the index when opening a fresh input.
  • Apply the larger 90-frame seek buffer only to MPEG-TS, preserving the existing 12-frame buffer for other formats.
  • Discard retained packets before repositioning the demuxer.

Validation

  • 29/29 FFmpegReader C++ regression tests passed.
  • 28/28 PNG SHA-256 frame comparisons passed.
  • Tested MPEG-TS and MP4 files with GOP lengths of 90 and 180 frames.
  • Verified frames 1, 30, 90, 180, 270, 300, and 359.
  • Verified seeking to a later indexed MPEG-TS keyframe.
  • git diff --check passed.

Scope

Changes are limited to:

  • src/FFmpegReader.cpp
  • src/FFmpegReader.h

Correct video PTS conversion and working-frame timestamp alignment.

Index MPEG-TS video keyframes and use their byte positions for
reliable seeking. Preserve the index across internal reader reopens.

Use a larger seek buffer only for MPEG-TS streams.

Addresses OpenShot#1031.
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