write_video
- torchvision.io.write_video(filename: str, video_array: Tensor, fps: float, video_codec: str = 'libx264', options: Optional[Dict[str, Any]] = None, audio_array: Optional[Tensor] = None, audio_fps: Optional[float] = None, audio_codec: Optional[str] = None, audio_options: Optional[Dict[str, Any]] = None) None [source]
[DEPRECATED] Writes a 4d tensor in [T, H, W, C] format in a video file.
Warning
DEPRECATED: All the video decoding and encoding capabilities of torchvision are deprecated from version 0.22 and will be removed in version 0.24. We recommend that you migrate to TorchCodec, where we’ll consolidate the future decoding/encoding capabilities of PyTorch
This function relies on PyAV (therefore, ultimately FFmpeg) to encode videos, you can get more fine-grained control by referring to the other options at your disposal within the FFMpeg wiki.
- Parameters:
filename (str) – path where the video will be saved
video_array (Tensor[T, H, W, C]) – tensor containing the individual frames, as a uint8 tensor in [T, H, W, C] format
fps (Number) – video frames per second
video_codec (str) – the name of the video codec, i.e. “libx264”, “h264”, etc.
options (Dict) –
dictionary containing options to be passed into the PyAV video stream. The list of options is codec-dependent and can all be found from the FFMpeg wiki.
audio_array (Tensor[C, N]) – tensor containing the audio, where C is the number of channels and N is the number of samples
audio_fps (Number) – audio sample rate, typically 44100 or 48000
audio_codec (str) – the name of the audio codec, i.e. “mp3”, “aac”, etc.
audio_options (Dict) –
dictionary containing options to be passed into the PyAV audio stream. The list of options is codec-dependent and can all be found from the FFMpeg wiki.
- Examples::
>>> # Creating libx264 video with CRF 17, for visually lossless footage: >>> >>> from torchvision.io import write_video >>> # 1000 frames of 100x100, 3-channel image. >>> vid = torch.randn(1000, 100, 100, 3, dtype = torch.uint8) >>> write_video("video.mp4", options = {"crf": "17"})