Skip to content

Fix PTS, DTS and timestamps on frames from clipped videos.#230

Merged
Tomás Duarte (tomas-duarte) merged 2 commits into
mainfrom
fix/clip-relative-frame-timestamp
Jul 6, 2026
Merged

Fix PTS, DTS and timestamps on frames from clipped videos.#230
Tomás Duarte (tomas-duarte) merged 2 commits into
mainfrom
fix/clip-relative-frame-timestamp

Conversation

@tomas-duarte

@tomas-duarte Tomás Duarte (tomas-duarte) commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Replaces #229, as I was not able to edit that PR.

Fixes decoded frame timestamps for clipped VideoFile inputs so sub-clips use a clip-local clock. iter_frames() now rebases PyAV frame pts/dts to the first emitted frame instead of the requested clip boundary. This keeps DecodedVideoFrame.timestamp_s, DecodedVideoFrame.pts, and the underlying PyAV frame.time/frame.pts in sync. This matches the ffmpeg trim and setpts filters.

Also change the delta to the first found frame instead of the clip
point. This matches the behaviour from ffmpeg's `trim` filter.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the video decoding logic to rebase the presentation timestamps (PTS), decoding timestamps (DTS), and timestamps of decoded video frames relative to the first emitted frame, ensuring that decoded sub-clips start at 0. It also replaces a custom timestamp helper with PyAV's native frame.time property and adds proper type annotations. Corresponding tests have been updated and added to verify the rebasing behavior. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@tomas-duarte
Tomás Duarte (tomas-duarte) merged commit 45ae7af into main Jul 6, 2026
5 checks passed
@tomas-duarte
Tomás Duarte (tomas-duarte) deleted the fix/clip-relative-frame-timestamp branch July 6, 2026 17:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 141c1b937f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

frame.pts = max(0, frame.pts - pts_delta)
if frame.dts is not None:
# negative dts may be required for proper ordering, can't clamp
frame.dts -= pts_delta

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Declare PyAV minimum before rewriting DTS

Because the video extra still allows any av version (pyproject.toml:33-35), environments that already have PyAV <13.1 installed can satisfy the dependency; PyAV only added the AVFrame.dts setter in 13.1, so for decoded frames with dts populated this assignment raises instead of yielding the clipped frame. Please either declare a minimum PyAV version or avoid writing dts when the setter is unavailable.

Useful? React with 👍 / 👎.

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