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 'output.mov' 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(cv2.cv.CV_CAP_PROP_FRAME_WIDTH ))
    h=int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT ))
    fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)

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

    while(vid.isOpened()):
        ret, frame = cap.read()

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

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

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

Comments

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