Ask Your Question

Revision history [back]

Video not recording. No errors

Hi! I am new in this forum and also pretty new with opencv. I am trying to make some image processing codes, and I found a problem when trying to record video from my webcam. My code is supposed to display the webcam and record the images in a file. When I run it I don't get any errors, and the webcam is displayed correctly, but no file is created.

This is the minimum code:

import cv2
cap = cv2.VideoCapture(0)
## Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out_writer = cv2.VideoWriter('output.avi',fourcc, 25, (640,480),isColor=True)
a = True
while a:
    a, frame = cap.read()
    out_writer.write(frame)
    cv2.imshow('Video',frame)
    # Break if <Esc> key
    k = cv2.waitKey(5) & 0xFF
    if k == 27:
      a = False
## Release everything if job is finished
cap.release()
out_writer.release()
cv2.destroyAllWindows()

When I run it I only get:

$ python save_video.py 
init done 
opengl support available

And no "output.avi" file is created.

Any idea of what I am doing wrong??!! Thanks for any help you can give me!!