-
Notifications
You must be signed in to change notification settings - Fork 35
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9d6bcff
WIP
NicolasHug a4a034a
Fix pts <-> seconds conversions
NicolasHug 4ba7db2
Merge branch 'fix-timebase' into dts_fallback
NicolasHug ce04b3c
Fallback to DTS when PTS info is missing
NicolasHug 06cd220
Fix compile issue
NicolasHug 142abda
Merge branch 'fix-timebase' into dts_fallback
NicolasHug 8bb3c08
Comment
NicolasHug 9a2c5be
Add test
NicolasHug 3437d3f
Merge branch 'main' of github.com:pytorch/torchcodec into dts_fallback
NicolasHug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -986,6 +986,47 @@ def get_some_frames(decoder): | |
assert_frames_equal(ref_frame3, frames[1].data) | ||
assert_frames_equal(ref_frame5, frames[2].data) | ||
|
||
@pytest.mark.parametrize("seek_mode", ("exact", "approximate")) | ||
def test_pts_to_dts_fallback(self, seek_mode): | ||
# Non-regression test for | ||
# https://github.com/pytorch/torchcodec/issues/677 and | ||
# https://github.com/pytorch/torchcodec/issues/676. | ||
# More accurately, this is a non-regression test for videos which do | ||
# *not* specify pts values (all pts values are N/A and set to | ||
# INT64_MIN), but specify *dts* value - which we fallback to. | ||
# | ||
# The test video we have is from | ||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create an issue? |
||
# find a way to do that with FFmpeg's CLI, but this should be doable | ||
# once we have our own video encoder. | ||
pytest.skip(reason="TODO: Need video with no pts values.") | ||
|
||
path = "/home/nicolashug/Downloads/sample_video_2.avi" | ||
decoder = VideoDecoder(path, seek_mode=seek_mode) | ||
metadata = decoder.metadata | ||
|
||
assert metadata.average_fps == pytest.approx(29.916667) | ||
assert metadata.duration_seconds_from_header == 9.02507 | ||
assert metadata.duration_seconds == 9.02507 | ||
assert metadata.begin_stream_seconds_from_content == ( | ||
None if seek_mode == "approximate" else 0 | ||
) | ||
assert metadata.end_stream_seconds_from_content == ( | ||
None if seek_mode == "approximate" else 9.02507 | ||
) | ||
|
||
assert decoder[0].shape == (3, 240, 320) | ||
decoder[10].shape == (3, 240, 320) | ||
decoder.get_frame_at(2).data.shape == (3, 240, 320) | ||
decoder.get_frames_at([2, 10]).data.shape == (2, 3, 240, 320) | ||
decoder.get_frame_played_at(9).data.shape == (3, 240, 320) | ||
decoder.get_frames_played_at([2, 4]).data.shape == (2, 3, 240, 320) | ||
with pytest.raises(AssertionError, match="not equal"): | ||
torch.testing.assert_close(decoder[0], decoder[10]) | ||
|
||
|
||
class TestAudioDecoder: | ||
@pytest.mark.parametrize("asset", (NASA_AUDIO, NASA_AUDIO_MP3, SINE_MONO_S32)) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.