Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Video Not Saving - Python Binding OpenCV

I am following along with this tutorial: http://docs.opencv.org/trunk/doc/py_tutorials/py_gui/py_video_display/py_video_display.html#saving-a-video

The program starts and activates the webcam but it does not write anything to disk. The file is created but the size is 0KB.

I receive the following error when trying to play the video: "Windows Media Player cannot play the file. The Player might not support the file type or might not support the codec that was used to compress the file."

My source-code is below:

import numpy as np
import cv2 

cap = cv2.VideoCapture(0)


#Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC('D', 'I', 'V', 'X')
out = cv2.VideoWriter('output.AVI', fourcc, 20.0, (640,480), 1)

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
        frame = cv2.flip(frame,0)

        #write the flipped frame
        out.write(frame)

        cv2.imshow('frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

#Release everything if job is finished
cap.release()
#out.release()
cv2.destroyAllWindows()

Why are the frames not written to disk?

Regards,