@@ -30,6 +30,7 @@ class FFmpegStream:
3030 Args:
3131 video_path (str): path to video file
3232 config (dict): conversion parameter
33+ skip_frames (int): skip given number of frames between queued frames
3334 start_frame (int): start frame number
3435 queue_size (int): size of frame buffer
3536 watchdog_timeout (int): watchdog timeout in seconds
@@ -38,6 +39,7 @@ class FFmpegStream:
3839 def __init__ (self ,
3940 video_path :str ,
4041 config :dict ,
42+ skip_frames :int = 0 ,
4143 start_frame :int = 0 ,
4244 queue_size :int = 256 ,
4345 watchdog_timeout :int = 4 ):
@@ -51,6 +53,7 @@ def __init__(self,
5153 self .timeout = False
5254 self .current_frame = 0
5355 self .sleep_time = 0.001
56+ self .skip_frames = skip_frames
5457
5558 self .video_info = self .get_video_info (video_path )
5659 self .frame_buffer = Queue (maxsize = queue_size )
@@ -357,12 +360,18 @@ def run(self) -> None:
357360 if frame is None :
358361 break
359362
363+ self .current_frame += 1
364+
365+ # NOTE: Use != 1 to ensure that the first difference is equal to the folowing (reqired for the interpolation)
366+ if self .skip_frames > 0 and self .current_frame % (self .skip_frames + 1 ) != 1 :
367+ continue
368+
360369 wait_counter = 0
361370 while self .frame_buffer .full () and not self .stopped :
362371 self .watchdog .trigger ()
363372 time .sleep (self .sleep_time )
364373 wait_counter += 1
365- if self .current_frame - self .queue_size > 2 and wait_counter == 2500 :
374+ if self .current_frame - ( self .skip_frames + 1 ) * self . queue_size > 3 and wait_counter == 2500 :
366375 self .logger .error ("FFmpeg Frame Buffer overrun!!!" )
367376
368377 if 'zoom' in self .config .keys ():
@@ -375,7 +384,6 @@ def run(self) -> None:
375384 frame = cv2 .resize (frame , self .config ['resize' ])
376385
377386 self .frame_buffer .put (frame )
378- self .current_frame += 1
379387
380388 self .stopped = True
381389 self .logger .info ('Close FFmpeg Stream' )
0 commit comments