Skip to content

Use duration of last frame#21

Merged
moi15moi merged 5 commits intomainfrom
Use-duration-of-last-frame
Dec 5, 2025
Merged

Use duration of last frame#21
moi15moi merged 5 commits intomainfrom
Use-duration-of-last-frame

Conversation

@moi15moi
Copy link
Owner

@moi15moi moi15moi commented Nov 1, 2025

This is needed for VFR video.
This depend on this PR: FFMS/ffms2#464
I'm waiting the ffms2 PR before merging this one.

@moi15moi moi15moi force-pushed the Use-duration-of-last-frame branch from 3d8b0a0 to afc3e68 Compare November 1, 2025 15:14
@codecov-commenter
Copy link

codecov-commenter commented Nov 1, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.98492% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.77%. Comparing base (9c05900) to head (d12579e).

Files with missing lines Patch % Lines
video_timestamps/abc_timestamps.py 87.50% 3 Missing ⚠️
video_timestamps/text_file_timestamps.py 96.07% 2 Missing ⚠️
video_timestamps/video_timestamps.py 90.90% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #21      +/-   ##
==========================================
- Coverage   97.84%   97.77%   -0.07%     
==========================================
  Files          17       17              
  Lines        1622     1666      +44     
==========================================
+ Hits         1587     1629      +42     
- Misses         35       37       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@moi15moi moi15moi force-pushed the Use-duration-of-last-frame branch 2 times, most recently from 741ed4c to 548bc2f Compare November 12, 2025 01:44
@moi15moi
Copy link
Owner Author

moi15moi commented Nov 19, 2025

This PR cause problem for CFR video when trying to calculate the PTS over the video duration.
It happen when the container/codec frame duration doesn't have the same timebase as the pts.

For example, for mkv file, the duration can be setted with BlockDuration or it will fallback to the track default Duration. For both of them, their value doesn't seems to depend on the same timebase has the PTS because, if we extract the timestamps of this sample_9_frames.zip, we get this:

# timestamp format v2
Frame 0: 0
Frame 1: 42
Frame 2: 83
Frame 3: 125
Frame 4: 167
Frame 5: 209
Frame 6: 250
Frame 7: 292
Frame 8: 334
Frame 8 + duration: 375.708333 which will be truncated to 375 by ffmpeg

375.708333 correspond to the last frame pts (334) + the default duration (41708333), so it give this number that doesn't respect the timebase 1/1000.
Normally, the frame 9 would be 375, so we could think that we just need to floor the result like ffmpeg does, but it isn't the case. Let's see a another example to example why.

With this sample, sample_8_frames.zip, we have those timestamps:

# timestamp format v2
Frame 0: 0
Frame 1: 42
Frame 2: 83
Frame 3: 125
Frame 4: 167
Frame 5: 209
Frame 6: 250
Frame 7: 292
Frame 7 + duration: 333.708333 which will be truncated to 333 by ffmpeg

Normally, the frame 8 would be 334, so in this case, we would need to round the result.

So, in brief, since it add the PTS of the last frame (which is rounded) + the default duration, the result is basically junk.
Also, ffmpeg store the frame duration with the same timebase as the PTS, so it actually trunk the duration.

There isn't any way to solve this issue.
This PR is great for VFR video, but for CFR video, it break the logic to resolve the timestamps over the video duration.
I don't know what I should do.

@moi15moi moi15moi force-pushed the Use-duration-of-last-frame branch from 548bc2f to 85e5190 Compare November 22, 2025 22:26
@moi15moi moi15moi force-pushed the Use-duration-of-last-frame branch from 8c47547 to 47e41b8 Compare December 5, 2025 01:42
moi15moi and others added 5 commits December 4, 2025 20:45
To test this, I generated a video with specific timestamps.
The video is almost CFR except that the last frame duration is 25 ms instead of 50.
We don't need to duplicate the logic.
…ith VideoTimestamps and v2/v4 timestamps file
@moi15moi moi15moi force-pushed the Use-duration-of-last-frame branch from 47e41b8 to d12579e Compare December 5, 2025 01:55
@moi15moi moi15moi merged commit f119725 into main Dec 5, 2025
30 checks passed
@moi15moi moi15moi deleted the Use-duration-of-last-frame branch December 5, 2025 04:03
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