title: Python OpenCV video recording fast-forwarding
body: <p>I've made a short script that is the beginings of a rubik's cube timer, but when I play back the recorded video it is extremely sped up.</p>
  
  <p>My webcam is a <a href="https://www.amazon.co.uk/Creative-Labs-Live-Cam-Chat/dp/B0043VTBI4/ref=sr_1_15?s=computers&amp;ie=UTF8&amp;qid=1480362780&amp;sr=1-15" rel="nofollow noreferrer">'Creative Labs Live! Cam Chat HD'</a> and has a resolution of 1280*720 pixels, Side note; when I try and run the script encoding in that resolution playback fails, and a framerate of 30 fps.</p>
  
  <p>Below is the code and a link of a video demonstrating the effect.</p>
  
  <pre><code>from time import clock as t
  import time
  import cv2
  import numpy as np
  cap = cv2.VideoCapture(0)
  fourcc = cv2.VideoWriter_fourcc(*"XVID")
  out = cv2.VideoWriter("output.avi", fourcc, 30.0, (640, 480))
  timing = False
  
  while True:
      ret, frame = cap.read()
      #frame = cv2.flip(frame, 1)
      cv2.imshow("frame", frame)
  
      if timing:
          out.write(frame)
  
      if cv2.waitKey(1) &amp; 0xFF == ord(" "):
          if timing:
              after = t()
              break
          else:
              timing = True
              start = t()
  
  cap.release()
  out.release()
  cv2.destroyAllWindows()
  
  print(after - start)
  </code></pre>
  
  <p><a href="https://www.dropbox.com/s/phhejvmu2lb8z1g/output.avi?dl=0" rel="nofollow noreferrer">Example of the accelerated video.</a></p>