title: Python OpenCV Error(-215) in VideoWriter.write
body: <p>I am trying to a write a python3-opencv3 code to read the color video and convert it to grayscale and save it back.
  (Trying exercises to learn python &amp; opencv)</p>
  
  <p>As I am working in ubuntu, I found out cv2.VideoCapture isColor flag will not work (it works only windows)</p>
  
  <hr>
  
  <pre><code>import numpy as np
  import cv2
  cap = cv2.VideoCapture('output.avi')
  ret, frame = cap.read()
  print('ret =', ret, 'W =', frame.shape[1], 'H =', frame.shape[0], 'channel =', frame.shape[2])
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  height, width = gray.shape[:2]
  print(height,width)
  cv2.imshow('frame',gray)
  FPS= 20.0
  FrameSize=(frame.shape[1], frame.shape[0]) 
  fourcc = cv2.VideoWriter_fourcc(*'MJPG')
  out = cv2.VideoWriter('Video_output.avi', fourcc, FPS, (width,height))
  
  while(ret):
      ret, frame = cap.read()
      if cv2.waitKey(1) &amp; 0xFF == ord('q') or ret == False:
          break
      print('ret =', ret, 'W =', frame.shape[1], 'H =', frame.shape[0], 'channel =', frame.shape[2])
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      # Save the video
      out.write(gray) 
      cv2.imshow('frame',gray)
  cap.release()
  out.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <hr>
  
  <p>It is give me this 
  error: (-215) img.cols == width &amp;&amp; img.rows == height*3 in function write</p>
  
  <p>I am guessing, the problem is with framesize and grayscale image conversion but I am not able to figure out ? I have tried different combination of height &amp; widht but none are able execute the program correctly. </p>
  
  <p>Can someone help ?</p>
  
  <p>As requested in the comments:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/akash/Coded/VideoCode/Test3", line 70, in &lt;module&gt;
      out.write(gray) 
  cv2.error: /home/travis/miniconda/conda-bld/conda_1486587069159/work/opencv-3.1.0/modules/videoio/src/cap_mjpeg_encoder.cpp:834: error: (-215) img.cols == width &amp;&amp; img.rows == height*3 in function write
  </code></pre>