Skip to content

Commit 484e2c8

Browse files
committed
Final doc touches before release (#650)
1 parent f2e2192 commit 484e2c8

File tree

5 files changed

+95
-25
lines changed

5 files changed

+95
-25
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# TorchCodec
44

5-
TorchCodec is a Python library for decoding videos into PyTorch tensors, on CPU
6-
and CUDA GPU. It aims to be fast, easy to use, and well integrated into the
7-
PyTorch ecosystem. If you want to use PyTorch to train ML models on videos,
8-
TorchCodec is how you turn those videos into data.
5+
TorchCodec is a Python library for decoding video and audio data into PyTorch
6+
tensors, on CPU and CUDA GPU. It aims to be fast, easy to use, and well
7+
integrated into the PyTorch ecosystem. If you want to use PyTorch to train ML
8+
models on videos and audio, TorchCodec is how you turn these into data.
99

1010
We achieve these capabilities through:
1111

docs/source/conf.py

+31
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,44 @@
5757
"sphinx_copybutton",
5858
]
5959

60+
61+
class CustomGalleryExampleSortKey:
62+
# This class defines the order in which our examples appear in
63+
# https://pytorch.org/torchcodec/stable/generated_examples/index.html
64+
# They would otherwise be sorted alphabetically.
65+
#
66+
# See https://sphinx-gallery.github.io/stable/configuration.html#sorting-gallery-examples
67+
# and https://github.com/sphinx-gallery/sphinx-gallery/blob/master/sphinx_gallery/sorting.py
68+
def __init__(self, src_dir):
69+
self.src_dir = src_dir
70+
71+
order = [
72+
"basic_example.py",
73+
"audio_decoding.py",
74+
"basic_cuda_example.py",
75+
"file_like.py",
76+
"approximate_mode.py",
77+
"sampling.py",
78+
]
79+
80+
def __call__(self, filename):
81+
try:
82+
return self.order.index(filename)
83+
except ValueError as e:
84+
raise ValueError(
85+
"Looks like you added an example in the examples/ folder?"
86+
"You need to specify its order in docs/source/conf.py. Look for CustomGalleryExampleSortKey."
87+
) from e
88+
89+
6090
sphinx_gallery_conf = {
6191
"examples_dirs": "../../examples/", # path to your example scripts
6292
"gallery_dirs": "generated_examples", # path to where to save gallery generated output
6393
"filename_pattern": ".py",
6494
"backreferences_dir": "gen_modules/backreferences",
6595
"doc_module": ("torchcodec",),
6696
"remove_config_comments": True,
97+
"within_subsection_order": CustomGalleryExampleSortKey,
6798
}
6899

69100
# We override sphinx-gallery's example header to prevent sphinx-gallery from

docs/source/index.rst

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Welcome to the TorchCodec documentation!
22
========================================
33

4-
TorchCodec is a Python library for decoding videos into PyTorch tensors, on CPU
5-
and CUDA GPU. It aims to be fast, easy to use, and well integrated into the
6-
PyTorch ecosystem. If you want to use PyTorch to train ML models on videos,
7-
TorchCodec is how you turn those videos into data.
4+
TorchCodec is a Python library for decoding video and audio data into PyTorch
5+
tensors, on CPU and CUDA GPU. It aims to be fast, easy to use, and well
6+
integrated into the PyTorch ecosystem. If you want to use PyTorch to train ML
7+
models on videos and audio, TorchCodec is how you turn these into data.
88

99
We achieve these capabilities through:
1010

@@ -36,12 +36,12 @@ We achieve these capabilities through:
3636
A simple video decoding example
3737

3838
.. grid-item-card:: :octicon:`file-code;1em`
39-
Clip sampling
39+
Audio Decoding
4040
:img-top: _static/img/card-background.svg
41-
:link: generated_examples/sampling.html
41+
:link: generated_examples/audio_decoding.html
4242
:link-type: url
4343

44-
How to sample regular and random clips from a video
44+
A simple audio decoding example
4545

4646
.. grid-item-card:: :octicon:`file-code;1em`
4747
GPU decoding
@@ -51,6 +51,22 @@ We achieve these capabilities through:
5151

5252
A simple example demonstrating CUDA GPU decoding
5353

54+
.. grid-item-card:: :octicon:`file-code;1em`
55+
Streaming video
56+
:img-top: _static/img/card-background.svg
57+
:link: generated_examples/file_like.html
58+
:link-type: url
59+
60+
How to efficiently decode videos from the cloud
61+
62+
.. grid-item-card:: :octicon:`file-code;1em`
63+
Clip sampling
64+
:img-top: _static/img/card-background.svg
65+
:link: generated_examples/sampling.html
66+
:link-type: url
67+
68+
How to sample regular and random clips from a video
69+
5470
.. note::
5571

5672
TorchCodec is still in development stage and we are actively seeking

examples/basic_example.py

+10
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ def plot(frames: torch.Tensor, title : Optional[str] = None):
9393
# :class:`~torchcodec.decoders.VideoDecoder`. Frames are always of
9494
# ``torch.uint8`` dtype.
9595
#
96+
# .. note::
97+
#
98+
# If you need to decode multiple frames, we recommend using the batch
99+
# methods instead, since they are faster:
100+
# :meth:`~torchcodec.decoders.VideoDecoder.get_frames_at`,
101+
# :meth:`~torchcodec.decoders.VideoDecoder.get_frames_in_range`,
102+
# :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_at`, and
103+
# :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_in_range`. They
104+
# are described below.
105+
96106

97107
plot(first_frame, "First frame")
98108

src/torchcodec/decoders/_video_decoder.py

+27-14
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ def _getitem_slice(self, key: slice) -> Tensor:
150150
def __getitem__(self, key: Union[numbers.Integral, slice]) -> Tensor:
151151
"""Return frame or frames as tensors, at the given index or range.
152152
153+
.. note::
154+
155+
If you need to decode multiple frames, we recommend using the batch
156+
methods instead, since they are faster:
157+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_at`,
158+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_in_range`,
159+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_at`, and
160+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_in_range`.
161+
153162
Args:
154163
key(int or slice): The index or range of frame(s) to retrieve.
155164
@@ -171,6 +180,15 @@ def _get_key_frame_indices(self) -> list[int]:
171180
def get_frame_at(self, index: int) -> Frame:
172181
"""Return a single frame at the given index.
173182
183+
.. note::
184+
185+
If you need to decode multiple frames, we recommend using the batch
186+
methods instead, since they are faster:
187+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_at`,
188+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_in_range`,
189+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_at`,
190+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_in_range`.
191+
174192
Args:
175193
index (int): The index of the frame to retrieve.
176194
@@ -194,13 +212,6 @@ def get_frame_at(self, index: int) -> Frame:
194212
def get_frames_at(self, indices: list[int]) -> FrameBatch:
195213
"""Return frames at the given indices.
196214
197-
.. note::
198-
199-
Calling this method is more efficient that repeated individual calls
200-
to :meth:`~torchcodec.decoders.VideoDecoder.get_frame_at`. This
201-
method makes sure not to decode the same frame twice, and also
202-
avoids "backwards seek" operations, which are slow.
203-
204215
Args:
205216
indices (list of int): The indices of the frames to retrieve.
206217
@@ -252,6 +263,15 @@ def get_frames_in_range(self, start: int, stop: int, step: int = 1) -> FrameBatc
252263
def get_frame_played_at(self, seconds: float) -> Frame:
253264
"""Return a single frame played at the given timestamp in seconds.
254265
266+
.. note::
267+
268+
If you need to decode multiple frames, we recommend using the batch
269+
methods instead, since they are faster:
270+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_at`,
271+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_in_range`,
272+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_at`,
273+
:meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_in_range`.
274+
255275
Args:
256276
seconds (float): The time stamp in seconds when the frame is played.
257277
@@ -276,13 +296,6 @@ def get_frame_played_at(self, seconds: float) -> Frame:
276296
def get_frames_played_at(self, seconds: list[float]) -> FrameBatch:
277297
"""Return frames played at the given timestamps in seconds.
278298
279-
.. note::
280-
281-
Calling this method is more efficient that repeated individual calls
282-
to :meth:`~torchcodec.decoders.VideoDecoder.get_frame_played_at`.
283-
This method makes sure not to decode the same frame twice, and also
284-
avoids "backwards seek" operations, which are slow.
285-
286299
Args:
287300
seconds (list of float): The timestamps in seconds when the frames are played.
288301

0 commit comments

Comments
 (0)