Skip to content

Commit 0880493

Browse files
committed
Draft for better write_video documentation
1 parent 0d80848 commit 0880493

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

torchvision/io/video.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,38 @@ def write_video(
6262
audio_options: Optional[Dict[str, Any]] = None,
6363
) -> None:
6464
"""
65-
Writes a 4d tensor in [T, H, W, C] format in a video file
65+
Writes a 4d tensor in [T, H, W, C] format in a video file.
66+
The default parameters (i.e. `fps`, `audio_fps`) return videos
67+
of a fixed quality & compressing speed, and may not necessarily be suitable for all applications.
68+
Since torchvision relies on `PyAV` (therefore, ultimately `FFmpeg`) to encode videos,
69+
you can get more fine-grained control by referring to the other options at
70+
your disposal within `the FFMpeg wiki <http://trac.ffmpeg.org/wiki#Encoding>`_.
6671
6772
Args:
6873
filename (str): path where the video will be saved
6974
video_array (Tensor[T, H, W, C]): tensor containing the individual frames,
7075
as a uint8 tensor in [T, H, W, C] format
7176
fps (Number): video frames per second
7277
video_codec (str): the name of the video codec, i.e. "libx264", "h264", etc.
73-
options (Dict): dictionary containing options to be passed into the PyAV video stream
78+
options (Dict): dictionary containing options to be passed into the PyAV video stream.
79+
The list of options is codec-dependent and can all
80+
be found from `the FFMpeg wiki <http://trac.ffmpeg.org/wiki#Encoding>`_.
7481
audio_array (Tensor[C, N]): tensor containing the audio, where C is the number of channels
7582
and N is the number of samples
7683
audio_fps (Number): audio sample rate, typically 44100 or 48000
7784
audio_codec (str): the name of the audio codec, i.e. "mp3", "aac", etc.
78-
audio_options (Dict): dictionary containing options to be passed into the PyAV audio stream
85+
audio_options (Dict): dictionary containing options to be passed into the PyAV audio stream.
86+
The list of options is codec-dependent and can all
87+
be found from `the FFMpeg wiki <http://trac.ffmpeg.org/wiki#Encoding>`_.
88+
89+
Examples::
90+
>>> # Creating libx264 video with CRF 17, for visually lossless footage:
91+
>>>
92+
>>> from torchvision.io import write_video
93+
>>> # 1000 frames of 100x100, 3-channel image.
94+
>>> vid = torch.randn(1000, 100, 100, 3, dtype = torch.uint8)
95+
>>> write_video("video.mp4", options = {"crf": "17"})
96+
7997
"""
8098
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
8199
_log_api_usage_once(write_video)

0 commit comments

Comments
 (0)