Skip to content

Commit aad97bc

Browse files
committed
Undo more tutorial changes
1 parent ef2e047 commit aad97bc

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

examples/decoding/approximate_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"-stream_loop", "99", # repeat video 100 times
5353
"-i", f"{short_video_path}",
5454
"-c", "copy",
55-
f"{long_video_path}",
55+
f"{long_video_path}"
5656
]
5757
subprocess.run(ffmpeg_command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
5858

examples/decoding/basic_example.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
:class:`~torchcodec.decoders.VideoDecoder` class.
1414
"""
1515

16-
1716
# %%
1817
# First, a bit of boilerplate: we'll download a video from the web, and define a
1918
# 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):
4241
print("Cannot plot, please run `pip install torchvision matplotlib`")
4342
return
4443

45-
plt.rcParams["savefig.bbox"] = "tight"
44+
plt.rcParams['savefig.bbox'] = 'tight'
4645
fig, ax = plt.subplots()
4746
ax.imshow(to_pil_image(make_grid(frames)))
4847
ax.set(xticklabels=[], yticklabels=[], xticks=[], yticks=[])
@@ -76,7 +75,7 @@ def plot(frames: torch.Tensor, title: str | None = None):
7675
# ---------------------------------------
7776

7877
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
8079

8180
print(f"{first_frame.shape = }")
8281
print(f"{first_frame.dtype = }")
@@ -116,7 +115,10 @@ def plot(frames: torch.Tensor, title: str | None = None):
116115
# The decoder is a normal iterable object and can be iterated over like so:
117116

118117
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+
)
120122

121123
# %%
122124
# Retrieving pts and duration of frames

examples/decoding/custom_frame_mappings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"-stream_loop", "50", # repeat video 50 times to get a ~12 min video
5252
"-i", f"{short_video_path}",
5353
"-c", "copy",
54-
f"{long_video_path}",
54+
f"{long_video_path}"
5555
]
5656
subprocess.run(ffmpeg_command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
5757

examples/decoding/parallel_decoding.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
pool manager.
2525
"""
2626

27-
2827
# %%
2928
# Let's first define some utility functions for benchmarking and data
3029
# processing. We'll also download a video and create a longer version by
@@ -80,10 +79,10 @@ def split_indices(indices: list[int], num_chunks: int) -> list[list[int]]:
8079
chunks = []
8180

8281
for i in range(num_chunks - 1):
83-
chunks.append(indices[i * chunk_size : (i + 1) * chunk_size])
82+
chunks.append(indices[i * chunk_size:(i + 1) * chunk_size])
8483

8584
# Last chunk may be slightly larger
86-
chunks.append(indices[(num_chunks - 1) * chunk_size :])
85+
chunks.append(indices[(num_chunks - 1) * chunk_size:])
8786
return chunks
8887

8988

@@ -107,7 +106,7 @@ def generate_long_video(temp_dir: str):
107106
"-stream_loop", "49", # repeat video 50 times
108107
"-i", str(short_video_path),
109108
"-c", "copy",
110-
str(long_video_path),
109+
str(long_video_path)
111110
]
112111
subprocess.run(ffmpeg_command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
113112

@@ -178,7 +177,7 @@ def decode_sequentially(indices: list[int], video_path=long_video_path):
178177
def decode_with_ffmpeg_parallelism(
179178
indices: list[int],
180179
num_threads: int,
181-
video_path=long_video_path,
180+
video_path=long_video_path
182181
):
183182
"""Decode frames using FFmpeg's internal threading."""
184183
decoder = VideoDecoder(video_path, num_ffmpeg_threads=num_threads, seek_mode="approximate")

examples/decoding/sampling.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
input to video models.
1515
"""
1616

17-
1817
# %%
1918
# First, a bit of boilerplate: we'll download a video from the web, and define a
2019
# plotting utility. You can ignore that part and jump right below to
@@ -43,7 +42,7 @@ def plot(frames: torch.Tensor, title: str | None = None):
4342
print("Cannot plot, please run `pip install torchvision matplotlib`")
4443
return
4544

46-
plt.rcParams["savefig.bbox"] = "tight"
45+
plt.rcParams['savefig.bbox'] = 'tight'
4746
fig, ax = plt.subplots()
4847
ax.imshow(to_pil_image(make_grid(frames)))
4948
ax.set(xticklabels=[], yticklabels=[], xticks=[], yticks=[])
@@ -191,7 +190,7 @@ def plot(frames: torch.Tensor, title: str | None = None):
191190
num_frames_per_clip=4,
192191
seconds_between_frames=0.5,
193192
sampling_range_start=2,
194-
sampling_range_end=5,
193+
sampling_range_end=5
195194
)
196195
clips
197196

examples/encoding/video_encoding.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ def play_video(encoded_bytes):
178178
# to check available options for your selected codec.
179179

180180
# Standard pixel format
181-
yuv420_encoded_frames = encoder.to_tensor(format="mp4", codec="libx264", pixel_format="yuv420p")
181+
yuv420_encoded_frames = encoder.to_tensor(
182+
format="mp4", codec="libx264", pixel_format="yuv420p"
183+
)
182184
play_video(yuv420_encoded_frames)
183185

184186
# %%
@@ -271,8 +273,8 @@ def play_video(encoded_bytes):
271273
custom_output,
272274
codec="libx264",
273275
extra_options={
274-
"g": 50, # Keyframe every 50 frames
275-
"max_b_frames": 0, # Disable B-frames for faster decoding
276+
"g": 50, # Keyframe every 50 frames
277+
"max_b_frames": 0, # Disable B-frames for faster decoding
276278
"tune": "fastdecode", # Optimize for fast decoding
277279
},
278280
)

0 commit comments

Comments
 (0)