title: Record a Webcam video with python
body: <p>I am trying to capture a video from a webcam stream. The python logic is </p>
  
  <blockquote>
    <p>If button is pressed, store the current stream until I press the stop
    button.</p>
  </blockquote>
  
  <p>Note : I am using OpenCV to stream a webcam video inside a wxPython window.</p>
  
  <pre><code>  def record(self, evt):
        cap = cv2.VideoCapture(0)
  
        # Define the codec and create VideoWriter object
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
        out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
  </code></pre>
  
  <p>I have tried the above code but it only stores 5.54kb file in the output dirctory?</p>
  
  <p>How to do it?</p>