@@ -66,7 +66,7 @@ class LazyImporter:
6666 """
6767
6868 MODULES = (
69- "av " ,
69+ "torchcodec " ,
7070 "lmdb" ,
7171 "pycocotools" ,
7272 "requests" ,
@@ -669,17 +669,24 @@ class VideoDatasetTestCase(DatasetTestCase):
669669
670670 - Overwrites the 'FEATURE_TYPES' class attribute to expect two :class:`torch.Tensor` s for the video and audio as
671671 well as an integer label.
672- - Overwrites the 'REQUIRED_PACKAGES' class attribute to require PyAV (``av``).
672+ - Overwrites the 'REQUIRED_PACKAGES' class attribute to require TorchCodec (``torchcodec``).
673+ - Skips on non-Linux platforms and CUDA-only environments.
673674 - Adds the 'DEFAULT_FRAMES_PER_CLIP' class attribute. If no 'frames_per_clip' is provided by 'inject_fake_data()'
674675 and it is the last parameter without a default value in the dataset constructor, the value of the
675676 'DEFAULT_FRAMES_PER_CLIP' class attribute is appended to the output.
676677 """
677678
678679 FEATURE_TYPES = (torch .Tensor , torch .Tensor , int )
679- REQUIRED_PACKAGES = ("av " ,)
680+ REQUIRED_PACKAGES = ("torchcodec " ,)
680681
681682 FRAMES_PER_CLIP = 1
682683
684+ @classmethod
685+ def setUpClass (cls ):
686+ if platform .system () != "Linux" :
687+ raise unittest .SkipTest ("Video dataset tests are only supported on Linux." )
688+ super ().setUpClass ()
689+
683690 def __init__ (self , * args , ** kwargs ):
684691 super ().__init__ (* args , ** kwargs )
685692 self .dataset_args = self ._set_default_frames_per_clip (self .dataset_args )
@@ -864,13 +871,12 @@ def shape_test_for_stereo(
864871 assert dw == mw
865872
866873
867- @requires_lazy_imports ("av " )
874+ @requires_lazy_imports ("torchcodec " )
868875def create_video_file (
869876 root : Union [pathlib .Path , str ],
870877 name : Union [pathlib .Path , str ],
871878 size : Union [Sequence [int ], int ] = (1 , 3 , 10 , 10 ),
872879 fps : float = 25 ,
873- ** kwargs : Any ,
874880) -> pathlib .Path :
875881 """Create a video file from random data.
876882
@@ -881,14 +887,15 @@ def create_video_file(
881887 ``(num_frames, num_channels, height, width)``. If scalar, the value is used for the height and width.
882888 If not provided, ``num_frames=1`` and ``num_channels=3`` are assumed.
883889 fps (float): Frame rate in frames per second.
884- kwargs (Any): Additional parameters passed to :func:`torchvision.io.write_video`.
885890
886891 Returns:
887- pathlib.Path: Path to the created image file.
892+ pathlib.Path: Path to the created video file.
888893
889894 Raises:
890- UsageError: If PyAV is not available.
895+ UsageError: If TorchCodec is not available.
891896 """
897+ from torchcodec .encoders import VideoEncoder
898+
892899 if isinstance (size , int ):
893900 size = (size , size )
894901 if len (size ) == 2 :
@@ -902,11 +909,14 @@ def create_video_file(
902909
903910 video = create_image_or_video_tensor (size )
904911 file = pathlib .Path (root ) / name
905- torchvision .io .write_video (str (file ), video .permute (0 , 2 , 3 , 1 ), fps , ** kwargs )
912+
913+ encoder = VideoEncoder (video , frame_rate = fps )
914+ encoder .to_file (str (file ))
915+
906916 return file
907917
908918
909- @requires_lazy_imports ("av " )
919+ @requires_lazy_imports ("torchcodec " )
910920def create_video_folder (
911921 root : Union [str , pathlib .Path ],
912922 name : Union [str , pathlib .Path ],
@@ -933,7 +943,7 @@ def create_video_folder(
933943 List[pathlib.Path]: Paths to all created video files.
934944
935945 Raises:
936- UsageError: If PyAV is not available.
946+ UsageError: If TorchCodec is not available.
937947
938948 .. seealso::
939949
@@ -944,7 +954,7 @@ def create_video_folder(
944954 def size (idx ):
945955 num_frames = 1
946956 num_channels = 3
947- # The 'libx264' video codec, which is the default of torchvision.io.write_video, requires the height and
957+ # The 'libx264' video codec requires the height and
948958 # width of the video to be divisible by 2.
949959 height , width = (torch .randint (2 , 6 , size = (2 ,), dtype = torch .int ) * 2 ).tolist ()
950960 return (num_frames , num_channels , height , width )
0 commit comments