|
13 | 13 | :class:`~torchcodec.decoders.VideoDecoder` class. |
14 | 14 | """ |
15 | 15 |
|
16 | | - |
17 | 16 | # %% |
18 | 17 | # First, a bit of boilerplate: we'll download a video from the web, and define a |
19 | 18 | # plotting utility. You can ignore that part and jump right below to |
@@ -42,7 +41,7 @@ def plot(frames: torch.Tensor, title: str | None = None): |
42 | 41 | print("Cannot plot, please run `pip install torchvision matplotlib`") |
43 | 42 | return |
44 | 43 |
|
45 | | - plt.rcParams["savefig.bbox"] = "tight" |
| 44 | + plt.rcParams['savefig.bbox'] = 'tight' |
46 | 45 | fig, ax = plt.subplots() |
47 | 46 | ax.imshow(to_pil_image(make_grid(frames))) |
48 | 47 | ax.set(xticklabels=[], yticklabels=[], xticks=[], yticks=[]) |
@@ -76,7 +75,7 @@ def plot(frames: torch.Tensor, title: str | None = None): |
76 | 75 | # --------------------------------------- |
77 | 76 |
|
78 | 77 | first_frame = decoder[0] # using a single int index |
79 | | -every_twenty_frame = decoder[0:-1:20] # using slices |
| 78 | +every_twenty_frame = decoder[0 : -1 : 20] # using slices |
80 | 79 |
|
81 | 80 | print(f"{first_frame.shape = }") |
82 | 81 | print(f"{first_frame.dtype = }") |
@@ -116,7 +115,10 @@ def plot(frames: torch.Tensor, title: str | None = None): |
116 | 115 | # The decoder is a normal iterable object and can be iterated over like so: |
117 | 116 |
|
118 | 117 | for frame in decoder: |
119 | | - assert isinstance(frame, torch.Tensor) and frame.shape == (3, decoder.metadata.height, decoder.metadata.width) |
| 118 | + assert ( |
| 119 | + isinstance(frame, torch.Tensor) |
| 120 | + and frame.shape == (3, decoder.metadata.height, decoder.metadata.width) |
| 121 | + ) |
120 | 122 |
|
121 | 123 | # %% |
122 | 124 | # Retrieving pts and duration of frames |
|
0 commit comments