Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for v1 timestamps file #10

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

moi15moi
Copy link
Owner

Fix #6

The previous algorithm supposed that first_timestamps was created from pts/time_scale, so it was always a multiple of time_scale.

But, even if it is generally the case, it isn't for v1 timestamps file.

In [this example](https://github.com/moi15moi/VideoTimestamps/blob/f9f1b64ef0c0f9e0f2b84210d325fc4080e57101/tests/test_text_file_timestamps.py#L9-L38), when we get over the frame 11, we need to calculate the time from the last frame pts.
Since the time_scale is 1000, the last frame pts is 567, but that pts is rounded. In reality, the last pts is 1700/3 = 566.666 (pts are never float, but that's just to show that it is slightly rounded).
Since we use the last frame pts to create a FPSTimestamps object, there is some rounding error since we start at the pts 567.

The solution for this is to use the last frame timestamps which is (1700/3)/1000 second as our first_timestamps to create a FPSTimestamps object.
But, (1700/3)/1000 isn't a multiple of time_scale (1000), we need to use a new formula that include the first_timestamps when it round or floor.
There isn't any reason to keep it since it isn't used anywhere.
This allow us to use the new doc algorithm (Algorithm conversion explanation.md).

Also, update the test to use the new API.
…last_timestamps

The approximate_pts_from_last_timestamps was a hack that didn't always work.
With last_timestamps, there isn't any hack and if the user provide the right value, it's perfect in term of precision.
As says in the commit b0403f436dd9251e61772600fe3169f508307aa1, the user needs to provide ``last_timestamps`` when they need precise results while requesting a frame or timestamp over the video duration.
@moi15moi moi15moi force-pushed the Add-support-for-v1-timestamps-file branch from 6af8407 to 2d60264 Compare February 19, 2025 22:38
We need this because, for FPSTimestamps, the first_timestamps provided by the user may not be the product of first_timestamps and time_scale may not produce a integer.

As a reminder, timestamps = pts / time_scale.
The new constructor of VideoTimestamps can use the last_timestamps (non-rounded), so we don't need this parameter anymore
@moi15moi moi15moi force-pushed the Add-support-for-v1-timestamps-file branch from 2d60264 to 278da8b Compare February 19, 2025 22:43
@moi15moi moi15moi force-pushed the Add-support-for-v1-timestamps-file branch from 278da8b to 4a116a4 Compare February 19, 2025 22:46
@codecov-commenter
Copy link

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

Codecov Report

Attention: Patch coverage is 92.74611% with 14 lines in your changes missing coverage. Please review.

Project coverage is 97.31%. Comparing base (231afe9) to head (4a116a4).

Files with missing lines Patch % Lines
video_timestamps/timestamps_file_parser.py 80.88% 13 Missing ⚠️
video_timestamps/text_file_timestamps.py 88.88% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
- Coverage   97.87%   97.31%   -0.56%     
==========================================
  Files          16       16              
  Lines        1364     1492     +128     
==========================================
+ Hits         1335     1452     +117     
- Misses         29       40      +11     

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

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.

Add support for v1 timestamps file
2 participants