title: OpenCV VideoWriter Not Writing to Output.avi
body: <p>I'm attempting to write a simple bit of code that takes a video, crops it, and writes to an output file.</p>
  
  <h1>System Setup:</h1>
  
  <pre><code>OS: Windows 10
  Conda Environment Python Version: 3.7
  OpenCV Version: 3.4.2
  ffmpeg Version: 2.7.0
  </code></pre>
  
  <h1>File Input Specs:</h1>
  
  <pre><code>Codec: H264 - MPEG-4 AVC (part 10)(avc1)
  Type: Video
  Video resolution: 640x360
  Frame rate: 5.056860
  </code></pre>
  
  <h1>Code failing to produce output (it creates the file but doesn't write to it):</h1>
  
  <pre><code>import numpy as np
  import cv2
  
  cap = cv2.VideoCapture('croptest1.mp4')
  
  # Define the codec and create VideoWriter object
  fourcc = cv2.VideoWriter_fourcc('F', 'M', 'P', '4')
  out = cv2.VideoWriter('output.avi', fourcc, 20.0,
                        (int(cap.get(3)), int(cap.get(4))))
  
  # Verify input shape
  width = cap.get(3)
  height = cap.get(4)
  fps = cap.get(5)
  print(width, height, fps)
  
  while(cap.isOpened()):
      ret, frame = cap.read()
      if ret == True:
          # from top left =frame[y0:y1, x0:x1]
          cropped_frame = frame[20:360, 0:640]
  
          # write the clipped frames
          out.write(cropped_frame)
  
          # show the clipped video
          cv2.imshow('cropped_frame', cropped_frame)
          if cv2.waitKey(1) &amp; 0xFF == ord('q'):
              break
      else:
          break
  
  # Release everything if job is finished
  cap.release()
  out.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <h1>Variations to fourcc and out variables tried to get codec to work:</h1>
  
  <pre><code>fourcc = cv2.cv.CV_FOURCC(*'DIVX')
  fourcc = cv2.VideoWriter_fourcc(*'DIVX')
  
  out = cv2.VideoWriter('ditch_effort.avi', -1, 20.0, (640, 360))
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/29320976/python-opencv-videowrite-doesnt-write-video">Based on this link</a> I should be able to refer to <a href="http://www.fourcc.org/codecs.php" rel="noreferrer">this fourcc reference list</a> to determine the appropriate fourcc compression code to use.  I have tried a bunch of variations, but cannot get the output file to be written.  When I run the code, the #verify input shape variables print the corresponding 640, 360 and correct Frame Rate.</p>
  
  <p>Can any one tell me what my issue is...would be much appreciated.</p>