Skip to content

Fallback to DTS if PTS info doesn't exist #683

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 9 commits into from
May 15, 2025

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented May 15, 2025

Some videos, like https://huggingface.co/datasets/raushan-testing-hf/videos-test/blob/main/sample_video_2.avi mentioned in #673, do not have any PTS value for their packets.

Up until now, this caused various weird issues like #677 and #676, and some silently-wrong error (e.g. index-based API with exact mode were always returning the first frame).

This PR allows for proper decoding of such poorly-encoded videos, by falling back to the DTS info if the PTS do not exist.

I added a test, which is skipped unconditionally. We should enable it back once we can check in such a poorly-encoded video. I made sure the test properly pass on https://huggingface.co/datasets/raushan-testing-hf/videos-test/blob/main/sample_video_2.avi with FFmpeg 4 and 6.

(needs #682 first. Note that the sample_video_2.avi video is one of those videos were timebase.den != 1, which exposed the bug that is fixed in #682).

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 15, 2025
Comment on lines +145 to +147
# Should never happen, but prevents ZeroDivisionError:
or self.end_stream_seconds_from_content
== self.begin_stream_seconds_from_content
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't actually needed anymore, i.e. the dts fallback already fixed the metadata issue. But it's probably safer to have this regardless?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, let's keep it. I think a single frame video is allowed, and we would encounter this problem with such a video.

# https://huggingface.co/datasets/raushan-testing-hf/videos-test/blob/main/sample_video_2.avi
# We can't check it into the repo due to potential licensing issues, so
# we have to unconditionally skip this test.#
# TODO: encode a video with no pts values to unskip this test. Couldn't
Copy link
Contributor

Choose a reason for hiding this comment

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

Create an issue?

Copy link
Contributor

@scotts scotts left a comment

Choose a reason for hiding this comment

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

Another great catch!

@NicolasHug NicolasHug merged commit a3867d1 into pytorch:main May 15, 2025
31 checks passed
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