title: OpenCV ret=False, is it reading the video, or not?
body: <p>I want to detect edges of a video file (640x640 9sn.) and save the result. I followed OpenCV documents and some other examples. Most of the examples that I found was reading from camera.</p>
  <p>Here is my code. I checked <code>cap.isOpened()</code>, it returns <code>True</code> but <code>ret</code> does <code>False</code> and <code>frame</code> is <em>NoneType</em> object. What is confusing is that I'm having the <code>gray</code> array which depends the condition <code>if ret == True</code>. How can I get gray matrix if <code>ret = False</code>?</p>
  <p>(I installed ffmpeg <code>pip install ffmpeg-python</code>)</p>
  <p>(andy.avi was saved in folder but it's broke, empty)</p>
  <pre><code>import cv2
  import numpy as np
  
  
  cap = cv2.VideoCapture(&quot;...\\video.mp4&quot;)
  
  while(cap.isOpened()):
      ret, frame = cap.read()
      
      frame_width = int(cap.get(3)) 
      frame_height = int(cap.get(4)) 
     
      size = (frame_width, frame_height) 
      
      result = cv2.VideoWriter('andy.avi',  
                           cv2.VideoWriter_fourcc(*'DIVX'), 
                           30, size) 
      
      if ret == True:
          gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
          edges = cv2.Canny(gray, 45, 90)
          result.write(edges)
          if cv2.waitKey(1) &amp; 0xFF == ord('q'):
              break
      else:
         break
                      
  cap.release()
  result.release()
  cv2.destroyAllWindows()
  
  </code></pre>