Fix PTS, DTS and timestamps on frames from clipped videos.#230
Conversation
Also change the delta to the first found frame instead of the clip point. This matches the behaviour from ffmpeg's `trim` filter.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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 |
There was a problem hiding this comment.
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 👍 / 👎.
Replaces #229, as I was not able to edit that PR.
Fixes decoded frame timestamps for clipped
VideoFileinputs so sub-clips use a clip-local clock.iter_frames()now rebases PyAV framepts/dtsto the first emitted frame instead of the requested clip boundary. This keepsDecodedVideoFrame.timestamp_s,DecodedVideoFrame.pts, and the underlying PyAVframe.time/frame.ptsin sync. This matches the ffmpegtrimandsetptsfilters.