Skip to content

Commit 9fe5d58

Browse files
author
Daniel Flores
committed
more nits
1 parent e360876 commit 9fe5d58

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

examples/decoding/custom_frame_mappings.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
"""
1515

1616
# %%
17-
# Create an HD video using ffmpeg and use the ffmpeg CLI to repeat it 100 times.
18-
# To get videos: a short video of approximately 30 seconds and a long one of about 22 mins.
19-
17+
# Create an HD video using ffmpeg and use the ffmpeg CLI to repeat it 10 times
18+
# to get two videos: a short video of approximately 30 seconds and a long one of about 10 mins.
2019

2120
import tempfile
2221
from pathlib import Path
@@ -43,19 +42,19 @@
4342
long_video_path = Path(temp_dir) / "long_video.mp4"
4443
ffmpeg_command = [
4544
"ffmpeg",
46-
"-stream_loop", "20", # repeat video 20 times to get a ~20 min video
45+
"-stream_loop", "20", # repeat video 20 times to get a 10 min video
4746
"-i", f"{short_video_path}",
4847
"-c", "copy",
4948
f"{long_video_path}"
5049
]
5150
subprocess.run(ffmpeg_command)
5251

53-
test_decoder = VideoDecoder(short_video_path)
54-
print(f"Short video duration: {test_decoder.metadata.duration_seconds} seconds")
52+
print(f"Short video duration: {VideoDecoder(short_video_path).metadata.duration_seconds} seconds")
5553
print(f"Long video duration: {VideoDecoder(long_video_path).metadata.duration_seconds / 60} minutes")
5654

5755
# %%
58-
# Preprocessing step
56+
# Preprocessing step to create frame mappings for the videos using ffprobe.
57+
5958
from pathlib import Path
6059
import subprocess
6160
import tempfile
@@ -80,7 +79,8 @@
8079
print(f"Wrote {len(ffprobe_result.stdout)} characters to {short_json_path}")
8180

8281
# %%
83-
# Define benchmarking function
82+
# Define benchmarking function. When a file_like object is passed in, its necessary to seek
83+
# to the beginning of the file before reading it in the next iteration.
8484

8585
import torch
8686

@@ -143,7 +143,6 @@ def decode_frames_from_n_videos(video_path, seek_mode = "exact", custom_frame_ma
143143
with open(json_path, "r") as f:
144144
bench(decode_frames_from_n_videos, video_path=video_path, custom_frame_mappings=(f.read()))
145145

146-
# Compare against seek_modes
147146
print("Decoding frames with seek_mode='exact':")
148147
bench(decode_frames_from_n_videos, video_path=video_path, seek_mode="exact")
149148

0 commit comments

Comments
 (0)