title: OpenCV: Writing a video from a cam, strange results (Python and Mac)
body: <p>I am trying to grab frames from a webcam and then writing them in a video. It works and the video shows something but it is useless.</p>
  
  <p>Here you can see an example of the videos I get: </p>
  
  <p><img src="https://i.imgur.com/mlG7m.png" alt="The kind of video I get"></p>
  
  <p>THe script is quite big so I will try to pick the relevant pieces for this problem:</p>
  
  <pre><code>import cv
  capture = cv.CaptureFromCAM(1) # from webcam
  frame  = cv.QueryFrame(capture)
  newvideo = 'Videos/%d_%d_%d_%d_%d_%d.avi' % (localtime()[0],localtime()[1],localtime()[2],localtime()[3],localtime()[4],localtime()[5])
  video = cv.CreateVideoWriter(newvideo, cv.CV_FOURCC('D','I','V','X'), 30, cv.GetSize(frame), 1)
  
  while(1):
  frame  = cv.QueryFrame(capture)
  cv.WriteFrame(video, frame)
  key = cv.WaitKey( int((1/30.)*1000)+1 )
  </code></pre>