1717 assert_tensor_close_on_at_least ,
1818 get_ffmpeg_major_version ,
1919 get_ffmpeg_minor_version ,
20- in_fbcode ,
2120 IS_WINDOWS ,
2221 NASA_AUDIO_MP3 ,
22+ needs_ffmpeg_cli ,
2323 psnr ,
2424 SINE_MONO_S32 ,
2525 TEST_SRC_2_720P ,
@@ -217,13 +217,22 @@ def test_bad_input_parametrized(self, method, tmp_path):
217217 getattr (decoder , method )(** valid_params , num_channels = num_channels )
218218
219219 @pytest .mark .parametrize ("method" , ("to_file" , "to_tensor" , "to_file_like" ))
220- @pytest .mark .parametrize ("format" , ("wav" , "flac" ))
220+ @pytest .mark .parametrize (
221+ "format" ,
222+ [
223+ pytest .param (
224+ "wav" ,
225+ marks = pytest .mark .skipif (
226+ get_ffmpeg_major_version () == 4 ,
227+ reason = "Swresample with FFmpeg 4 doesn't work on wav files" ,
228+ ),
229+ ),
230+ "flac" ,
231+ ],
232+ )
221233 def test_round_trip (self , method , format , tmp_path ):
222234 # Check that decode(encode(samples)) == samples on lossless formats
223235
224- if get_ffmpeg_major_version () == 4 and format == "wav" :
225- pytest .skip ("Swresample with FFmpeg 4 doesn't work on wav files" )
226-
227236 asset = NASA_AUDIO_MP3
228237 source_samples = self .decode (asset ).data
229238
@@ -249,7 +258,7 @@ def test_round_trip(self, method, format, tmp_path):
249258 self .decode (encoded_source ).data , source_samples , rtol = rtol , atol = atol
250259 )
251260
252- @pytest . mark . skipif ( in_fbcode (), reason = "TODO: enable ffmpeg CLI" )
261+ @needs_ffmpeg_cli
253262 @pytest .mark .parametrize ("asset" , (NASA_AUDIO_MP3 , SINE_MONO_S32 ))
254263 @pytest .mark .parametrize ("bit_rate" , (None , 0 , 44_100 , 999_999_999 ))
255264 @pytest .mark .parametrize ("num_channels" , (None , 1 , 2 ))
@@ -356,17 +365,31 @@ def test_against_cli(
356365 @pytest .mark .parametrize ("asset" , (NASA_AUDIO_MP3 , SINE_MONO_S32 ))
357366 @pytest .mark .parametrize ("bit_rate" , (None , 0 , 44_100 , 999_999_999 ))
358367 @pytest .mark .parametrize ("num_channels" , (None , 1 , 2 ))
359- @pytest .mark .parametrize ("format" , ("mp3" , "wav" , "flac" ))
368+ @pytest .mark .parametrize (
369+ "format" ,
370+ [
371+ # TODO: https://github.com/pytorch/torchcodec/issues/837
372+ pytest .param (
373+ "mp3" ,
374+ marks = pytest .mark .skipif (
375+ IS_WINDOWS and get_ffmpeg_major_version () <= 5 ,
376+ reason = "Encoding mp3 on Windows is weirdly buggy" ,
377+ ),
378+ ),
379+ pytest .param (
380+ "wav" ,
381+ marks = pytest .mark .skipif (
382+ get_ffmpeg_major_version () == 4 ,
383+ reason = "Swresample with FFmpeg 4 doesn't work on wav files" ,
384+ ),
385+ ),
386+ "flac" ,
387+ ],
388+ )
360389 @pytest .mark .parametrize ("method" , ("to_tensor" , "to_file_like" ))
361390 def test_against_to_file (
362391 self , asset , bit_rate , num_channels , format , tmp_path , method
363392 ):
364- if get_ffmpeg_major_version () == 4 and format == "wav" :
365- pytest .skip ("Swresample with FFmpeg 4 doesn't work on wav files" )
366- if IS_WINDOWS and get_ffmpeg_major_version () <= 5 and format == "mp3" :
367- # TODO: https://github.com/pytorch/torchcodec/issues/837
368- pytest .skip ("Encoding mp3 on Windows is weirdly buggy" )
369-
370393 encoder = AudioEncoder (self .decode (asset ).data , sample_rate = asset .sample_rate )
371394
372395 params = dict (bit_rate = bit_rate , num_channels = num_channels )
@@ -847,16 +870,27 @@ def encode_to_tensor(frames):
847870 )
848871
849872 @pytest .mark .parametrize (
850- "format" , ("mov" , "mp4" , "mkv" , pytest .param ("webm" , marks = pytest .mark .slow ))
873+ "format" ,
874+ [
875+ "mov" ,
876+ "mp4" ,
877+ "mkv" ,
878+ pytest .param (
879+ "webm" ,
880+ marks = [
881+ pytest .mark .slow ,
882+ pytest .mark .skipif (
883+ get_ffmpeg_major_version () == 4
884+ or (IS_WINDOWS and get_ffmpeg_major_version () in (6 , 7 )),
885+ reason = "Codec for webm is not available in this FFmpeg installation." ,
886+ ),
887+ ],
888+ ),
889+ ],
851890 )
852891 @pytest .mark .parametrize ("method" , ("to_file" , "to_tensor" , "to_file_like" ))
853892 def test_round_trip (self , tmp_path , format , method ):
854893 # Test that decode(encode(decode(frames))) == decode(frames)
855- ffmpeg_version = get_ffmpeg_major_version ()
856- if format == "webm" and (
857- ffmpeg_version == 4 or (IS_WINDOWS and ffmpeg_version in (6 , 7 ))
858- ):
859- pytest .skip ("Codec for webm is not available in this FFmpeg installation." )
860894 source_frames , frame_rate = self .decode_and_get_frame_rate (TEST_SRC_2_720P .path )
861895
862896 encoder = VideoEncoder (frames = source_frames , frame_rate = frame_rate )
@@ -889,25 +923,29 @@ def test_round_trip(self, tmp_path, format, method):
889923
890924 @pytest .mark .parametrize (
891925 "format" ,
892- (
926+ [
893927 "mov" ,
894928 "mp4" ,
895929 "avi" ,
896930 "mkv" ,
897931 "flv" ,
898932 "gif" ,
899- pytest .param ("webm" , marks = pytest .mark .slow ),
900- ),
933+ pytest .param (
934+ "webm" ,
935+ marks = [
936+ pytest .mark .slow ,
937+ pytest .mark .skipif (
938+ get_ffmpeg_major_version () == 4
939+ or (IS_WINDOWS and get_ffmpeg_major_version () in (6 , 7 )),
940+ reason = "Codec for webm is not available in this FFmpeg installation." ,
941+ ),
942+ ],
943+ ),
944+ ],
901945 )
902946 @pytest .mark .parametrize ("method" , ("to_tensor" , "to_file_like" ))
903947 def test_against_to_file (self , tmp_path , format , method ):
904948 # Test that to_file, to_tensor, and to_file_like produce the same results
905- ffmpeg_version = get_ffmpeg_major_version ()
906- if format == "webm" and (
907- ffmpeg_version == 4 or (IS_WINDOWS and ffmpeg_version in (6 , 7 ))
908- ):
909- pytest .skip ("Codec for webm is not available in this FFmpeg installation." )
910-
911949 source_frames , frame_rate = self .decode_and_get_frame_rate (TEST_SRC_2_720P .path )
912950 encoder = VideoEncoder (frames = source_frames , frame_rate = frame_rate )
913951
@@ -928,7 +966,7 @@ def test_against_to_file(self, tmp_path, format, method):
928966 rtol = 0 ,
929967 )
930968
931- @pytest . mark . skipif ( in_fbcode (), reason = "ffmpeg CLI not available" )
969+ @needs_ffmpeg_cli
932970 @pytest .mark .parametrize (
933971 "format" ,
934972 (
@@ -1150,10 +1188,7 @@ def write(self, data):
11501188 ):
11511189 encoder .to_file_like (NoSeekMethod (), format = "mp4" )
11521190
1153- @pytest .mark .skipif (
1154- in_fbcode (),
1155- reason = "ffprobe not available internally" ,
1156- )
1191+ @needs_ffmpeg_cli
11571192 @pytest .mark .parametrize (
11581193 "format,codec_spec" ,
11591194 [
@@ -1181,10 +1216,7 @@ def test_codec_parameter_utilized(self, tmp_path, format, codec_spec):
11811216 ]
11821217 assert actual_codec_spec == codec_spec
11831218
1184- @pytest .mark .skipif (
1185- in_fbcode (),
1186- reason = "ffprobe not available internally" ,
1187- )
1219+ @needs_ffmpeg_cli
11881220 @pytest .mark .parametrize (
11891221 "codec_spec,codec_impl" ,
11901222 [
@@ -1227,7 +1259,7 @@ def test_codec_spec_vs_impl_equivalence(self, tmp_path, codec_spec, codec_impl):
12271259 frames_impl = self .decode (impl_output )
12281260 torch .testing .assert_close (frames_spec , frames_impl , rtol = 0 , atol = 0 )
12291261
1230- @pytest . mark . skipif ( in_fbcode (), reason = "ffprobe not available" )
1262+ @needs_ffmpeg_cli
12311263 @pytest .mark .parametrize (
12321264 "profile,colorspace,color_range" ,
12331265 [
0 commit comments