title: cv2.VideoCapture on python
body: <p>I am running the following code:</p>
  
  <pre><code>import numpy as np
  import cv2
  import os
  
  count = 0
  
  cap = cv2.VideoCapture("/home/simon/PROJECT/real_data/00000020.mp4")
  
  while not cap.isOpened():
      cap = cv2.VideoCapture("./00000020.mp4")
      cv2.waitKey(1000)
      print "Wait for the header"
  
  pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
  while True:
      flag, frame = cap.read()
      if flag:
          # The frame is ready and already captured
          cv2.imshow('video', frame)
          pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
          print str(pos_frame)+" frames"
      else:
          # The next frame is not ready, so we try to read it again
          cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1)
          print "frame is not ready"
          # It is better to wait for a while for the next frame to be ready
          cv2.waitKey(1000)
  
      if cv2.waitKey(10) &amp; 0xFF == 27:
          break
      if cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) ==       cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT):
      # If the number of captured frames is equal to the total number of frames,
      # we stop
      break
  
  
  if ret == True:
      frame = cv2.VideoCapture.grab()
      frame = 'frame%d' % count 
  
      cv2.imwrite('frame%d.png', frame)
  
      count += 1
  else:
      print 'stopped at' + count
      break
  </code></pre>
  
  <p>And whenever I run it, it loops on the while not loop, printing "wait for header".
  There is never an error code or anything like that either.</p>
  
  <p>I have tried to run it as a more simple piece of code, where it doesnt have all these checks, and again that doesn't throw any errors.</p>
  
  <p>I am attempting to run this code to open a video, and then save the frames as png files throughout the video.</p>
  
  <p>Does anyone spot any particular problems with the code?
  Or alternatively does anyone know a piece of code that would do what i want more efficiently, as I have trawled through google searches and stack overflow a lot recently and haven't found anything</p>
  
  <p>Thanks in advance
  Panda</p>