title: Playback loop option in OpenCV videos
body: <p>I am trying to build a <strong>playback loop option for an OpenCV video</strong>. My program uses Python multiprocessing, and has a button send <code>loopswitch</code> calls through <code>queue4</code> to enable or disable the loop option. My specific problem is that my video freezes on the last frame, and <strong>I would like to know if the line <code>vidFile.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 1)</code> is a correct use of the <code>cv2.VideoCapture.set()</code> method</strong>, and should indeed take the video back to frame 1 and replay it (as I think it should).</p>
  
  <h2>EDIT</h2>
  
  <p>After revising my code, it now triggers a runtime C++ error, but no other precisions are given.
  According to <a href="https://stackoverflow.com/a/11260842/2322456">this answer</a>, it would seem that using <code>cv2.VideoCapture.set()</code> to jump between frame is buggy. Has anyone managed it anyway?</p>
  
  <p>Thank you,</p>
  
  <p>My code for the capture process (<code>queue</code>and <code>queue2</code> are in and out queues):</p>
  
  <pre><code>def image_capture(queue, con, queue2, queue4):
      videopath = con.recv()
      vidFile = cv2.VideoCapture(videopath)
      fps = vidFile.get(cv2.cv.CV_CAP_PROP_FPS)
      waitframe = 1/fps
      con.send(waitframe)#sending waitkey duration through pipe to update_image()
      loopswitch = False #init for playing video in a loop 
      while True:
          if queue4.empty():
             pass
          else:
             queueval = queue4.get()
              if queueval=='loop':
                 if loopswitch==False:
                    loopswitch = True
                 elif loopswitch==True:
                    loopswitch = False
          try:
              flag, frame=vidFile.read()
              if flag==0:
                 if loopswitch==False:
                    queue2.put(None)
                    break
                 elif loopswitch==True:
                    vidFile.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 1)
                    continue
              else:                
                 queue2.put(frame)
                 cv2.waitKey(waitframe)
          except:
              continue
  </code></pre>