@@ -306,50 +306,42 @@ def get_frame(
306306 Returns:
307307 np.ndarray: opencv image
308308 """
309- if False :
310- cap = cv2 .VideoCapture (video_path )
311- if frame_number > 0 :
312- cap .set (cv2 .CAP_PROP_POS_FRAMES , frame_number )
313- _ , frame = cap .read ()
314- cap .release ()
315- return frame
316- else :
317- video_info = FFmpegStream .get_video_info (video_path )
318- seek = FFmpegStream .frame_to_timestamp (frame_number , video_info .fps )
309+ video_info = FFmpegStream .get_video_info (video_path )
310+ seek = FFmpegStream .frame_to_timestamp (frame_number , video_info .fps )
319311
320- command = [
321- FFmpegStream .get_ffmpeg_command (),
322- '-hide_banner' ,
323- '-loglevel' , 'warning' ,
324- '-ss' , str (seek ),
325- '-hwaccel' , 'auto' ,
326- '-i' , video_path ,
327- '-f' , 'image2pipe' ,
328- '-pix_fmt' , 'bgr24' ,
329- '-vsync' , '0' ,
330- '-vcodec' , 'rawvideo' ,
331- '-an' ,
332- '-sn' ,
333- '-'
334- ]
312+ command = [
313+ FFmpegStream .get_ffmpeg_command (),
314+ '-hide_banner' ,
315+ '-loglevel' , 'warning' ,
316+ '-ss' , str (seek ),
317+ '-hwaccel' , 'auto' ,
318+ '-i' , video_path ,
319+ '-f' , 'image2pipe' ,
320+ '-pix_fmt' , 'bgr24' ,
321+ '-vsync' , '0' ,
322+ '-vcodec' , 'rawvideo' ,
323+ '-an' ,
324+ '-sn' ,
325+ '-'
326+ ]
335327
336- pipe = sp .Popen (
337- command ,
338- stdout = sp .PIPE ,
339- stderr = sp .PIPE ,
340- bufsize = 3 * video_info .height * video_info .width
341- )
328+ pipe = sp .Popen (
329+ command ,
330+ stdout = sp .PIPE ,
331+ stderr = sp .PIPE ,
332+ bufsize = 3 * video_info .height * video_info .width
333+ )
342334
343- data = pipe .stdout .read (video_info .width * video_info .height * 3 )
344- pipe .terminate ()
345- try : pipe .stdout .close ()
346- except : pass
347- try : pipe .stderr .close ()
348- except : pass
335+ data = pipe .stdout .read (video_info .width * video_info .height * 3 )
336+ pipe .terminate ()
337+ try : pipe .stdout .close ()
338+ except : pass
339+ try : pipe .stderr .close ()
340+ except : pass
349341
350- return np .frombuffer (data , dtype = 'uint8' ).reshape (
351- (video_info .height , video_info .width , 3 )
352- )
342+ return np .frombuffer (data , dtype = 'uint8' ).reshape (
343+ (video_info .height , video_info .width , 3 )
344+ )
353345
354346
355347 def run (self ) -> None :
0 commit comments