@@ -986,6 +986,47 @@ def get_some_frames(decoder):
986986 assert_frames_equal (ref_frame3 , frames [1 ].data )
987987 assert_frames_equal (ref_frame5 , frames [2 ].data )
988988
989+ @pytest .mark .parametrize ("seek_mode" , ("exact" , "approximate" ))
990+ def test_pts_to_dts_fallback (self , seek_mode ):
991+ # Non-regression test for
992+ # https://github.com/pytorch/torchcodec/issues/677 and
993+ # https://github.com/pytorch/torchcodec/issues/676.
994+ # More accurately, this is a non-regression test for videos which do
995+ # *not* specify pts values (all pts values are N/A and set to
996+ # INT64_MIN), but specify *dts* value - which we fallback to.
997+ #
998+ # The test video we have is from
999+ # https://huggingface.co/datasets/raushan-testing-hf/videos-test/blob/main/sample_video_2.avi
1000+ # We can't check it into the repo due to potential licensing issues, so
1001+ # we have to unconditionally skip this test.#
1002+ # TODO: encode a video with no pts values to unskip this test. Couldn't
1003+ # find a way to do that with FFmpeg's CLI, but this should be doable
1004+ # once we have our own video encoder.
1005+ pytest .skip (reason = "TODO: Need video with no pts values." )
1006+
1007+ path = "/home/nicolashug/Downloads/sample_video_2.avi"
1008+ decoder = VideoDecoder (path , seek_mode = seek_mode )
1009+ metadata = decoder .metadata
1010+
1011+ assert metadata .average_fps == pytest .approx (29.916667 )
1012+ assert metadata .duration_seconds_from_header == 9.02507
1013+ assert metadata .duration_seconds == 9.02507
1014+ assert metadata .begin_stream_seconds_from_content == (
1015+ None if seek_mode == "approximate" else 0
1016+ )
1017+ assert metadata .end_stream_seconds_from_content == (
1018+ None if seek_mode == "approximate" else 9.02507
1019+ )
1020+
1021+ assert decoder [0 ].shape == (3 , 240 , 320 )
1022+ decoder [10 ].shape == (3 , 240 , 320 )
1023+ decoder .get_frame_at (2 ).data .shape == (3 , 240 , 320 )
1024+ decoder .get_frames_at ([2 , 10 ]).data .shape == (2 , 3 , 240 , 320 )
1025+ decoder .get_frame_played_at (9 ).data .shape == (3 , 240 , 320 )
1026+ decoder .get_frames_played_at ([2 , 4 ]).data .shape == (2 , 3 , 240 , 320 )
1027+ with pytest .raises (AssertionError , match = "not equal" ):
1028+ torch .testing .assert_close (decoder [0 ], decoder [10 ])
1029+
9891030
9901031class TestAudioDecoder :
9911032 @pytest .mark .parametrize ("asset" , (NASA_AUDIO , NASA_AUDIO_MP3 , SINE_MONO_S32 ))
0 commit comments