|
14 | 14 | """ |
15 | 15 |
|
16 | 16 | # %% |
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. |
20 | 19 |
|
21 | 20 | import tempfile |
22 | 21 | from pathlib import Path |
|
43 | 42 | long_video_path = Path(temp_dir) / "long_video.mp4" |
44 | 43 | ffmpeg_command = [ |
45 | 44 | "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 |
47 | 46 | "-i", f"{short_video_path}", |
48 | 47 | "-c", "copy", |
49 | 48 | f"{long_video_path}" |
50 | 49 | ] |
51 | 50 | subprocess.run(ffmpeg_command) |
52 | 51 |
|
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") |
55 | 53 | print(f"Long video duration: {VideoDecoder(long_video_path).metadata.duration_seconds / 60} minutes") |
56 | 54 |
|
57 | 55 | # %% |
58 | | -# Preprocessing step |
| 56 | +# Preprocessing step to create frame mappings for the videos using ffprobe. |
| 57 | + |
59 | 58 | from pathlib import Path |
60 | 59 | import subprocess |
61 | 60 | import tempfile |
|
80 | 79 | print(f"Wrote {len(ffprobe_result.stdout)} characters to {short_json_path}") |
81 | 80 |
|
82 | 81 | # %% |
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. |
84 | 84 |
|
85 | 85 | import torch |
86 | 86 |
|
@@ -143,7 +143,6 @@ def decode_frames_from_n_videos(video_path, seek_mode = "exact", custom_frame_ma |
143 | 143 | with open(json_path, "r") as f: |
144 | 144 | bench(decode_frames_from_n_videos, video_path=video_path, custom_frame_mappings=(f.read())) |
145 | 145 |
|
146 | | - # Compare against seek_modes |
147 | 146 | print("Decoding frames with seek_mode='exact':") |
148 | 147 | bench(decode_frames_from_n_videos, video_path=video_path, seek_mode="exact") |
149 | 148 |
|
|
0 commit comments