@@ -24,7 +24,7 @@ def video_info(video_path: str) -> Tuple[int, int, int]:
24
24
# Get the list of all video streams
25
25
video_streams = [stream for stream in info ['streams' ] if stream ['codec_type' ] == 'video' ]
26
26
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 ))
28
28
29
29
# retrieve the first stream of type 'video'
30
30
info_video = video_streams [0 ]
@@ -53,7 +53,7 @@ def extract_video_info(video_path: str) -> VideoInfo:
53
53
# Get the list of all video streams
54
54
video_streams = [stream for stream in info ['streams' ] if stream ['codec_type' ] == 'video' ]
55
55
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 ))
57
57
58
58
# retrieve the first stream of type 'video'
59
59
info_video = video_streams [0 ]
@@ -124,7 +124,7 @@ def extract_frames_ffmpeg(video_file: str, timestamps_df: pd.DataFrame, output_d
124
124
frame_path = os .path .join (output_dir , str (timestamp ) + ".jpg" )
125
125
in_frame = cv2 .cvtColor (in_frame , cv2 .COLOR_RGB2BGR )
126
126
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)
128
128
129
129
else :
130
130
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
137
137
138
138
def rebuild_video (dir : Path , frames : pd .DataFrame , video_info : VideoInfo , outfile : Path ) -> None :
139
139
140
- # We don't know the target video size, yet .
140
+ # Extract the vido information .
141
141
frame_width = video_info .width
142
142
frame_height = video_info .height
143
143
fps = video_info .fps
@@ -162,6 +162,8 @@ def rebuild_video(dir: Path, frames: pd.DataFrame, video_info: VideoInfo, outfil
162
162
.run_async (pipe_stdin = True )
163
163
)
164
164
165
+ assert frame_width is not None and frame_height is not None and ffmpeg_video_out_process is not None
166
+
165
167
#
166
168
# Cycle through all the frames.
167
169
for idx , row in frames .iterrows ():
@@ -185,16 +187,11 @@ def rebuild_video(dir: Path, frames: pd.DataFrame, video_info: VideoInfo, outfil
185
187
raise Exception (f"The dimension of the read image ({ img_width } x{ img_height } )"
186
188
f" does not match the dimension of the generated video { frame_width } x{ frame_height } ." )
187
189
188
- assert frame_width is not None and frame_height is not None and ffmpeg_video_out_process is not None
189
-
190
190
# Send the frame to the ffmpeg process
191
191
ffmpeg_video_out_process .stdin .write (img .tobytes ())
192
192
193
193
elif gen == "Generated" :
194
194
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
-
198
195
# Create an artificial black frame
199
196
print (f"Injecting Black frame at idx { idx } " )
200
197
black_frame = np .zeros ((frame_height , frame_width , 3 ), dtype = np .uint8 )
0 commit comments