VideoWriter writing invalid videos

asked 2015-10-26 08:59:53 -0500

chr0x gravatar image

I'm using the code described below to record my webcam on macbook pro. The file being generated is not a valid video, and I can't open it in a video player When I try to use CV_FOURCC('X','V','I','D') the output is an '' file with 414kb (everytime I run the program this size is the same). I tried to change FOURCC to: CV_FOURCC('m', 'p', '4', 'v'). In that case the file are geting bigger for every second that I kept the webcam on, but I still can't open the video file. How can I record this video?

    cap = cv2.VideoCapture(0)

    w=int(cap.get( ))
    h=int(cap.get( ))
    fps = cap.get(

    fourcc ='X','V','I','D')
    vout = cv2.VideoWriter()
    capSize = (w, h)
    success ='',fourcc,fps,capSize,True)

        ret, frame =

        if ret == True:
            cv2.imshow("frame", frame)

            if cv2.waitKey(1) & 0xFF == ord('q'):

PS: When I tried to open the mp4v format the error ir:

it generates the error:

Application Specific Information: * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array' terminating with uncaught exception of type NSException abort() called

edit retag flag offensive close merge delete


Afaik, the output container must be .avi to work. So try to use "output.avi" as output filename

LorenaGdL gravatar imageLorenaGdL ( 2015-10-26 11:12:57 -0500 )edit