title: How to save masks of videos in openCV2 python
body: <p>I can capture a video from the webcam and save it fine with this code</p>
  
  <pre><code>cap = cv2.VideoCapture(0)
  fgbg= cv2.BackgroundSubtractorMOG()
  
  fourcc = cv2.cv.CV_FOURCC(*'DIVX')
  out    = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))
  
  while(cap.isOpened()):
      ret,frame = cap.read()
      if ret:
          fgmask = fgbg.apply(frame)
          out.write(frame)          #Save it                                      
          cv2.imshow('Background Subtraction', fgmask)
          if cv2.waitKey(1) &amp; 0xFF == ord('q'):
              break                 #q to quit                                    
      else:
          break                     #EOF                                          
  
  cap.release()
  out.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>This records it as one would expect, and shows the background subtraction thing also. It saves it to output.avi. All is well. But I can't save the foreground mask, it gives me a <code>Could not demultiplex stream</code> error. (This line is changed in the code above).</p>
  
  <pre><code>out.write(fgmask)          #Save it    
  </code></pre>
  
  <p>Why is this? Is the fgmask not a frame like when I am reading from the capture?</p>