5151INDEX_OF_FRAME_AT_6_SECONDS = 180
5252
5353
54- class TestOps :
54+ class TestVideoOps :
5555 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
5656 def test_seek_and_next (self , device ):
5757 decoder = create_from_file (str (NASA_VIDEO .path ))
@@ -616,6 +616,8 @@ def test_cuda_decoder(self):
616616 duration , torch .tensor (0.0334 ).double (), atol = 0 , rtol = 1e-3
617617 )
618618
619+
620+ class TestAudioOps :
619621 @pytest .mark .parametrize (
620622 "method" ,
621623 (
@@ -664,19 +666,15 @@ def test_audio_decode_all_samples_with_next(self, asset):
664666 @pytest .mark .parametrize (
665667 "range" , ("begin_to_end" , "at_frame_boundaries" , "not_at_frame_boundaries" )
666668 )
667- # @pytest.mark.parametrize("asset", (NASA_AUDIO, NASA_AUDIO_MP3))
668- @pytest .mark .parametrize ("asset" , (NASA_AUDIO ,))
669- def test_audio_get_frames_by_pts_in_range_audio (self , range , asset ):
669+ @pytest .mark .parametrize ("asset" , (NASA_AUDIO , NASA_AUDIO_MP3 ))
670+ def test_get_frames_by_pts_in_range_audio (self , range , asset ):
670671 if range == "begin_to_end" :
671672 start_seconds , stop_seconds = 0 , asset .duration_seconds
672673 elif range == "at_frame_boundaries" :
673674 start_seconds = asset .frames [asset .default_stream_index ][10 ].pts_seconds
674- # need -1e-5 because the upper bound in open. If we don't do this
675- # then our test util returns one frame too much.
676- stop_seconds = (
677- asset .frames [asset .default_stream_index ][40 ].pts_seconds - 1e-5
678- )
675+ stop_seconds = asset .frames [asset .default_stream_index ][40 ].pts_seconds
679676 else :
677+ assert range == "not_at_frame_boundaries"
680678 start_frame_info = asset .frames [asset .default_stream_index ][10 ]
681679 stop_frame_info = asset .frames [asset .default_stream_index ][40 ]
682680 start_seconds = start_frame_info .pts_seconds + (
@@ -689,20 +687,32 @@ def test_audio_get_frames_by_pts_in_range_audio(self, range, asset):
689687 decoder = create_from_file (str (asset .path ), seek_mode = "approximate" )
690688 add_audio_stream (decoder )
691689
690+ stop_offset = 0 if range == "at_frame_boundaries" else 1
692691 reference_frames = asset .get_frame_data_by_range (
693692 start = asset .get_frame_index (pts_seconds = start_seconds ),
694- stop = asset .get_frame_index (pts_seconds = stop_seconds ) + 1 ,
693+ stop = asset .get_frame_index (pts_seconds = stop_seconds ) + stop_offset ,
695694 )
696- reference_frames = torch .cat (reference_frames .unbind (), dim = - 1 )
697695
698696 frames = get_frames_by_pts_in_range_audio (
699697 decoder , start_seconds = start_seconds , stop_seconds = stop_seconds
700698 )
701699
702700 assert_frames_equal (frames , reference_frames )
703701
702+ @pytest .mark .parametrize (
703+ "asset, expected_shape" , ((NASA_AUDIO , (2 , 1024 )), (NASA_AUDIO_MP3 , (2 , 576 )))
704+ )
705+ def test_decode_epsilon_range (self , asset , expected_shape ):
706+ decoder = create_from_file (str (asset .path ), seek_mode = "approximate" )
707+ add_audio_stream (decoder )
708+
709+ frames = get_frames_by_pts_in_range_audio (
710+ decoder , start_seconds = 5 , stop_seconds = 5 + 1e-5
711+ )
712+ assert frames .shape == expected_shape
713+
704714 @pytest .mark .parametrize ("asset" , (NASA_AUDIO , NASA_AUDIO_MP3 ))
705- def test_audio_seek_and_next (self , asset ):
715+ def test_seek_and_next_audio (self , asset ):
706716 decoder = create_from_file (str (asset .path ), seek_mode = "approximate" )
707717 add_audio_stream (decoder )
708718
0 commit comments