Skip to content

Commit 3146a74

Browse files
N00bcakNicolasHug
andauthored
Draft for better write_video documentation (#8576)
Co-authored-by: Nicolas Hug <[email protected]>
1 parent 0534b6e commit 3146a74

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

torchvision/io/video.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ 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+
67+
This function relies on PyAV (therefore, ultimately FFmpeg) to encode
68+
videos, you can get more fine-grained control by referring to the other
69+
options at your disposal within `the FFMpeg wiki
70+
<http://trac.ffmpeg.org/wiki#Encoding>`_.
6671
6772
.. warning::
6873
@@ -78,12 +83,25 @@ def write_video(
7883
as a uint8 tensor in [T, H, W, C] format
7984
fps (Number): video frames per second
8085
video_codec (str): the name of the video codec, i.e. "libx264", "h264", etc.
81-
options (Dict): dictionary containing options to be passed into the PyAV video stream
86+
options (Dict): dictionary containing options to be passed into the PyAV video stream.
87+
The list of options is codec-dependent and can all
88+
be found from `the FFMpeg wiki <http://trac.ffmpeg.org/wiki#Encoding>`_.
8289
audio_array (Tensor[C, N]): tensor containing the audio, where C is the number of channels
8390
and N is the number of samples
8491
audio_fps (Number): audio sample rate, typically 44100 or 48000
8592
audio_codec (str): the name of the audio codec, i.e. "mp3", "aac", etc.
86-
audio_options (Dict): dictionary containing options to be passed into the PyAV audio stream
93+
audio_options (Dict): dictionary containing options to be passed into the PyAV audio stream.
94+
The list of options is codec-dependent and can all
95+
be found from `the FFMpeg wiki <http://trac.ffmpeg.org/wiki#Encoding>`_.
96+
97+
Examples::
98+
>>> # Creating libx264 video with CRF 17, for visually lossless footage:
99+
>>>
100+
>>> from torchvision.io import write_video
101+
>>> # 1000 frames of 100x100, 3-channel image.
102+
>>> vid = torch.randn(1000, 100, 100, 3, dtype = torch.uint8)
103+
>>> write_video("video.mp4", options = {"crf": "17"})
104+
87105
"""
88106
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
89107
_log_api_usage_once(write_video)

0 commit comments

Comments
 (0)