Ask Your Question

Video Not Saving - Python Binding OpenCV

asked 2015-01-14 17:16:23 -0500

underscore gravatar image

I am following along with this tutorial:

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 ='D', 'I', 'V', 'X')
out = cv2.VideoWriter('output.AVI', fourcc, 20.0, (640,480), 1)

    ret, frame =
    if ret == True:
        frame = cv2.flip(frame,0)

        #write the flipped frame

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

#Release everything if job is finished

Why are the frames not written to disk?


edit retag flag offensive close merge delete


Hi, I have the same problem use Phython 2.7.9 and version 2.7.9, can capture video but not saved. out.write (frame) seems to not work. CAN SOMEONE PLEASE HELP. SPANISH Hola, yo tengo el mismo problema uso Phython 2.7.9 y la versión de 2.7.9, puedo capturar video pero no guarda. out.write(frame) parece que no funciona. POR FAVOR ALGUIEN PUEDE AYUDARNOS.

alejandrovalenciaw gravatar imagealejandrovalenciaw ( 2015-04-27 03:14:30 -0500 )edit

2 answers

Sort by » oldest newest most voted

answered 2015-05-28 21:25:45 -0500

zzdts gravatar image

I have the same problem too ...

edit flag offensive delete link more

answered 2017-01-23 15:49:36 -0500

I had a problem in the resolution of the image. Try to change the size to the default size for your camera.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-01-14 17:16:23 -0500

Seen: 1,344 times

Last updated: Jan 14 '15