Skip to content

Commit a926934

Browse files
committed
.
1 parent 51e2308 commit a926934

File tree

3 files changed

+19
-177
lines changed

3 files changed

+19
-177
lines changed

docs/source/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ We achieve these capabilities through:
4242

4343
A simple video decoding example
4444

45+
.. grid-item-card:: :octicon:`file-code;1em`
46+
GPU decoding using TorchCodec
47+
:img-top: _static/img/card-background.svg
48+
:link: generated_examples/basic_cuda_example.html
49+
:link-type: url
50+
51+
A GPU decoding example
52+
4553
.. grid-item-card:: :octicon:`file-code;1em`
4654
API Reference
4755
:img-top: _static/img/card-background.svg

examples/basic_example.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
# :ref:`creating_decoder`.
2020

2121
from typing import Optional
22-
import torch
22+
2323
import requests
24+
import torch
2425

2526

2627
# Video source: https://www.pexels.com/video/dog-eating-854132/
@@ -33,16 +34,16 @@
3334
raw_video_bytes = response.content
3435

3536

36-
def plot(frames: torch.Tensor, title : Optional[str] = None):
37+
def plot(frames: torch.Tensor, title: Optional[str] = None):
3738
try:
38-
from torchvision.utils import make_grid
39-
from torchvision.transforms.v2.functional import to_pil_image
4039
import matplotlib.pyplot as plt
40+
from torchvision.transforms.v2.functional import to_pil_image
41+
from torchvision.utils import make_grid
4142
except ImportError:
4243
print("Cannot plot, please run `pip install torchvision matplotlib`")
4344
return
4445

45-
plt.rcParams["savefig.bbox"] = 'tight'
46+
plt.rcParams["savefig.bbox"] = "tight"
4647
fig, ax = plt.subplots()
4748
ax.imshow(to_pil_image(make_grid(frames)))
4849
ax.set(xticklabels=[], yticklabels=[], xticks=[], yticks=[])
@@ -76,7 +77,7 @@ def plot(frames: torch.Tensor, title : Optional[str] = None):
7677
# ---------------------------------------
7778

7879
first_frame = decoder[0] # using a single int index
79-
every_twenty_frame = decoder[0 : -1 : 20] # using slices
80+
every_twenty_frame = decoder[0:-1:20] # using slices
8081

8182
print(f"{first_frame.shape = }")
8283
print(f"{first_frame.dtype = }")
@@ -106,9 +107,10 @@ def plot(frames: torch.Tensor, title : Optional[str] = None):
106107
# The decoder is a normal iterable object and can be iterated over like so:
107108

108109
for frame in decoder:
109-
assert (
110-
isinstance(frame, torch.Tensor)
111-
and frame.shape == (3, decoder.metadata.height, decoder.metadata.width)
110+
assert isinstance(frame, torch.Tensor) and frame.shape == (
111+
3,
112+
decoder.metadata.height,
113+
decoder.metadata.width,
112114
)
113115

114116
# %%

examples/cuda_example.py

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)