Skip to content

Commit 78f63a3

Browse files
committed
Cleaned up assertions and comments.
1 parent 9dd7330 commit 78f63a3

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

PythonTools/video.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def video_info(video_path: str) -> Tuple[int, int, int]:
2424
# Get the list of all video streams
2525
video_streams = [stream for stream in info['streams'] if stream['codec_type'] == 'video']
2626
if len(video_streams) == 0:
27-
raise BaseException("No video streams found in file '{}'".format(video_path))
27+
raise Exception("No video streams found in file '{}'".format(video_path))
2828

2929
# retrieve the first stream of type 'video'
3030
info_video = video_streams[0]
@@ -53,7 +53,7 @@ def extract_video_info(video_path: str) -> VideoInfo:
5353
# Get the list of all video streams
5454
video_streams = [stream for stream in info['streams'] if stream['codec_type'] == 'video']
5555
if len(video_streams) == 0:
56-
raise BaseException("No video streams found in file '{}'".format(video_path))
56+
raise Exception("No video streams found in file '{}'".format(video_path))
5757

5858
# retrieve the first stream of type 'video'
5959
info_video = video_streams[0]
@@ -124,7 +124,7 @@ def extract_frames_ffmpeg(video_file: str, timestamps_df: pd.DataFrame, output_d
124124
frame_path = os.path.join(output_dir, str(timestamp) + ".jpg")
125125
in_frame = cv2.cvtColor(in_frame, cv2.COLOR_RGB2BGR)
126126
cv2.imwrite(frame_path, in_frame)
127-
#PIL.Image.fromarray(in_frame, 'RGB').save(frame_path)
127+
# PIL.Image.fromarray(in_frame, 'RGB').save(frame_path)
128128

129129
else:
130130
print(f"At frame {fnum}, no more frames to extract from video '{video_file}'. Expected {len(timestamps)} frames.")
@@ -137,7 +137,7 @@ def extract_frames_ffmpeg(video_file: str, timestamps_df: pd.DataFrame, output_d
137137

138138
def rebuild_video(dir: Path, frames: pd.DataFrame, video_info: VideoInfo, outfile: Path) -> None:
139139

140-
# We don't know the target video size, yet.
140+
# Extract the vido information.
141141
frame_width = video_info.width
142142
frame_height = video_info.height
143143
fps = video_info.fps
@@ -162,6 +162,8 @@ def rebuild_video(dir: Path, frames: pd.DataFrame, video_info: VideoInfo, outfil
162162
.run_async(pipe_stdin=True)
163163
)
164164

165+
assert frame_width is not None and frame_height is not None and ffmpeg_video_out_process is not None
166+
165167
#
166168
# Cycle through all the frames.
167169
for idx, row in frames.iterrows():
@@ -185,16 +187,11 @@ def rebuild_video(dir: Path, frames: pd.DataFrame, video_info: VideoInfo, outfil
185187
raise Exception(f"The dimension of the read image ({img_width}x{img_height})"
186188
f" does not match the dimension of the generated video {frame_width}x{frame_height}.")
187189

188-
assert frame_width is not None and frame_height is not None and ffmpeg_video_out_process is not None
189-
190190
# Send the frame to the ffmpeg process
191191
ffmpeg_video_out_process.stdin.write(img.tobytes())
192192

193193
elif gen == "Generated":
194194

195-
# The first frame can NOT be a generated one
196-
assert frame_width is not None and frame_height is not None and ffmpeg_video_out_process is not None
197-
198195
# Create an artificial black frame
199196
print(f"Injecting Black frame at idx {idx}")
200197
black_frame = np.zeros((frame_height, frame_width, 3), dtype=np.uint8)

0 commit comments

Comments
 (0)