Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft for better write_video documentation #8576

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions torchvision/io/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,38 @@ def write_video(
audio_options: Optional[Dict[str, Any]] = None,
) -> None:
"""
Writes a 4d tensor in [T, H, W, C] format in a video file
Writes a 4d tensor in [T, H, W, C] format in a video file.
The default parameters (i.e. `fps`, `audio_fps`) return videos
of a fixed quality & compressing speed, and may not necessarily be suitable for all applications.
Since torchvision 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 <http://trac.ffmpeg.org/wiki#Encoding>`_.

Args:
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
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 <http://trac.ffmpeg.org/wiki#Encoding>`_.
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
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 <http://trac.ffmpeg.org/wiki#Encoding>`_.

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"})

"""
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
_log_api_usage_once(write_video)
Expand Down