Skip to content

Consistently use ptsToSeconds #784

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

Merged
merged 2 commits into from
Jul 29, 2025
Merged

Conversation

Dan-Flores
Copy link
Contributor

@Dan-Flores Dan-Flores commented Jul 23, 2025

As discussed in #764, this PR updates various methods in SingleStreamDecoder.cpp to use ptsToSeconds when performing calculations with the time_base.

Additionally, ptsToSeconds is updated to use av_q2d to ensure the AVRationals are correctly handled.

Tests are updated as well to reflect the added precision:

  • In VideoDecoderTest.cpp, comparisons of ptsSeconds are updated from EXPECT_EQ to EXPECT_DOUBLE_EQ.
  • In test_ops.py, pytest.approx is used to compare pts_seconds.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 23, 2025
@Dan-Flores Dan-Flores force-pushed the use_pts_to_seconds branch from 916e4e2 to fffd499 Compare July 25, 2025 17:59
@Dan-Flores Dan-Flores marked this pull request as ready for review July 28, 2025 15:24
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @Dan-Flores

@@ -955,7 +955,7 @@ def test_pts(self, asset):
frames, asset.get_frame_data_by_index(frame_index)
)

assert pts_seconds == start_seconds
assert pts_seconds == pytest.approx(start_seconds)
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised we need to use approx so just to be on the safe side I removed it and we're getting:

FAILED test/test_ops.py::TestAudioDecoderOps::test_next[asset0] - assert 0.5760000000000001 == 0.576
FAILED test/test_ops.py::TestAudioDecoderOps::test_next[asset1] - assert 0.9359999999999999 == 0.936
FAILED test/test_ops.py::TestAudioDecoderOps::test_pts[asset0] - assert 0.5760000000000001 == 0.576
FAILED test/test_ops.py::TestAudioDecoderOps::test_pts[asset1] - assert 0.9359999999999999 == 0.936

Which is probably OK. But I still find it surprising considering the implementation of av_q2d is just

static inline double av_q2d(AVRational a){
     return a.num / (double) a.den;
 }

@Dan-Flores Dan-Flores merged commit eb3cc16 into pytorch:main Jul 29, 2025
43 of 44 checks passed
@Dan-Flores Dan-Flores deleted the use_pts_to_seconds branch July 29, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants