@@ -572,7 +572,7 @@ class TestVideoEncoder:
572572 def decode (self , source = None ) -> torch .Tensor :
573573 return VideoDecoder (source ).get_frames_in_range (start = 0 , stop = 60 )
574574
575- def _get_codec_name (self , file_path ):
575+ def _get_codec_spec (self , file_path ):
576576 """Helper function to get codec name from a video file using ffprobe."""
577577 result = subprocess .run (
578578 [
@@ -1011,8 +1011,12 @@ def write(self, data):
10111011 ):
10121012 encoder .to_file_like (NoSeekMethod (), format = "mp4" )
10131013
1014+ @pytest .mark .skipif (
1015+ in_fbcode (),
1016+ reason = "ffprobe not available internally" ,
1017+ )
10141018 @pytest .mark .parametrize (
1015- "format,codec " ,
1019+ "format,codec_spec " ,
10161020 [
10171021 ("mp4" , "h264" ),
10181022 ("mp4" , "hevc" ),
@@ -1021,54 +1025,45 @@ def write(self, data):
10211025 ("webm" , "vp9" ),
10221026 ],
10231027 )
1024- def test_codec_parameter_utilized (self , tmp_path , format , codec ):
1028+ def test_codec_parameter_utilized (self , tmp_path , format , codec_spec ):
10251029 # Test the codec parameter is utilized by using ffprobe to check the encoded file's codec spec
1026- frames = torch .randint ( 0 , 256 , (10 , 3 , 128 , 128 ), dtype = torch .uint8 )
1030+ frames = torch .zeros ( (10 , 3 , 64 , 64 ), dtype = torch .uint8 )
10271031 dest = str (tmp_path / f"output.{ format } " )
1028- VideoEncoder (frames = frames , frame_rate = 30 ).to_file (dest = dest , codec = codec )
10291032
1030- actual_codec = self . _get_codec_name (dest )
1031- print ( f"Expected codec: { codec } , Actual codec: { actual_codec } " )
1032- assert actual_codec == codec
1033+ VideoEncoder ( frames = frames , frame_rate = 30 ). to_file (dest = dest , codec = codec_spec )
1034+ actual_codec_spec = self . _get_codec_spec ( dest )
1035+ assert actual_codec_spec == codec_spec
10331036
1037+ @pytest .mark .skipif (
1038+ in_fbcode (),
1039+ reason = "ffprobe not available internally" ,
1040+ )
10341041 @pytest .mark .parametrize (
10351042 "codec_spec,codec_impl" ,
10361043 [
10371044 ("h264" , "libx264" ),
1038- ("hevc" , "libx265" ),
10391045 ("av1" , "libaom-av1" ),
10401046 ("vp9" , "libvpx-vp9" ),
10411047 ],
10421048 )
1043- def test_codec_spec_vs_implementation_equivalence (
1044- self , tmp_path , codec_spec , codec_impl
1045- ):
1049+ def test_codec_spec_vs_impl_equivalence (self , tmp_path , codec_spec , codec_impl ):
10461050 # Test that using codec spec gives the same result as using default codec implementation
1051+ # We cannot directly check codec impl used, so we assert frame equality
10471052 frames = torch .randint (0 , 256 , (10 , 3 , 64 , 64 ), dtype = torch .uint8 )
10481053
1049- spec_output = tmp_path / "spec_output.mp4"
1050- encoder_spec = VideoEncoder (frames = frames , frame_rate = 30 )
1051- encoder_spec .to_file (dest = str (spec_output ), codec = codec_spec , crf = 0 )
1052-
1053- impl_output = tmp_path / "impl_output.mp4"
1054- encoder_impl = VideoEncoder (frames = frames , frame_rate = 30 )
1055- encoder_impl .to_file (dest = str (impl_output ), codec = codec_impl , crf = 0 )
1056-
1057- # Verify both files use the same codec spec
1058- spec_codec_name = self ._get_codec_name (spec_output )
1059- impl_codec_name = self ._get_codec_name (impl_output )
1060-
1061- assert spec_codec_name == impl_codec_name
1062- assert spec_codec_name == codec_spec
1063-
1064- # Decode both and verify frames are identical
1065- from torchcodec .decoders import VideoDecoder
1054+ spec_output = str (tmp_path / "spec_output.mp4" )
1055+ VideoEncoder (frames = frames , frame_rate = 30 ).to_file (
1056+ dest = spec_output , codec = codec_spec
1057+ )
10661058
1067- decoder_spec = VideoDecoder (str (spec_output ))
1068- decoder_impl = VideoDecoder (str (impl_output ))
1059+ impl_output = str (tmp_path / "impl_output.mp4" )
1060+ VideoEncoder (frames = frames , frame_rate = 30 ).to_file (
1061+ dest = impl_output , codec = codec_impl
1062+ )
10691063
1070- frames_spec = decoder_spec . get_frames_in_range ( 0 , 10 ). data
1071- frames_impl = decoder_impl . get_frames_in_range ( 0 , 10 ). data
1064+ assert self . _get_codec_spec ( spec_output ) == codec_spec
1065+ assert self . _get_codec_spec ( impl_output ) == codec_spec
10721066
1073- # The decoded frames should be exactly the same
1067+ frames_spec = self .decode (spec_output ).data
1068+ frames_impl = self .decode (impl_output ).data
10741069 torch .testing .assert_close (frames_spec , frames_impl , rtol = 0 , atol = 0 )
0 commit comments