如何并行处理同一视频的不同部分?

时间:2019-06-11 09:53:19

标签: python opencv

我目前正在尝试并行处理视频。但是,我不能只使用一个视频捕获,然后让每个进程访问对应的部分。我想知道是否有一种方法可以创建视频片段,因此我不必在每个过程中分配整个视频。我想做这样的事情:

def process(video, init_frame, end_frame): 
    video.set(cv2.CAP_PROP_POS_MSEC,init_frame*1000.0/FPS) 
    for i in range(init_frame,end_frame) 
        im, t = video.read()
        #do something with the frame im

def main(file,number_process,fragment_size):

   video = cv2.VideoCapture(file)

   for i  in range(number_process):
      start = int(i*fragment_size)
      end = int(start+fragment_size)
      if i == number_models-1:
          end = int(num_frames)
      processes[i] = mp.Process(target=process,args=(video,start,end)       

但是,这将不起作用,因为阅读器将视频锁定在一个特定的帧中,因此只有一个过程能够使视频通过。我想知道是否还有其他方法可以实现类似目标?任何建议都非常欢迎。

0 个答案:

没有答案