title: Using Raspberry Pi + Webcam to record video in python always gets an empty video or only one frame video
body: <p>I want to record video with Raspberry Pi + wedcam (logitech). Although I found many examples which are actually almost the same code as following:</p>
  
  <pre><code>import numpy as np
  import cv2
  
  path = ('/.../output.avi')
  fourcc = cv2.cv.CV_FOURCC(*'XVID')
  out = cv2.VideoWriter(path,fourcc, 20.0, (640,480))
  
  while(cap.isOpened()):
      #read the frame
      ret, frame = cap.read()
      if ret==True:
          #Write the frame
          video_writer.write(frame)
          #show the frame
          cv2.imshow('frame',frame)
          if cv2.waitKey(1) &amp; 0xFF == ord('q'):
              break
      else:
          break
  
  # Release everything if job is finished
  cap.release()
  video_writer.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>First question, I have tried all solutions from <a href="https://stackoverflow.com/questions/26452909/opencv-write-frame-to-file-python">OpenCV write frame to file python</a>
  but it seems those solutions didn't suitable for me...
  so I want to know if anyone has other solutions for this problem, I will appreciate!
  Second question, I found that someone use </p>
  
  <pre><code>cv2.VideoWriter_fourcc('XVID')
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>cv2.cv.CV_FOURCC(*'XVID')
  </code></pre>
  
  <p>Would that be the problem? Also, I have tried to use cv2.VideoWriter_fourcc('XVID'), but get an error: 'module' object has no attribute 'VideoWriter_fourcc'... How can I solve this?
  Thanks!</p>