3

I am using OpenCV with python 2.7.3 on Linux 64-bit machine. I wanted to fetch frames from my Logitech C270 and store it as an AVI video. The code is working fine, it also shows me the video getting captured and the output file is also created. But when i try to play the file it is not playing at all as well as i am getting 'cv2.VideoWriter object has no attribute release' error on terminal. So, if someone can tell me how to release the cv2.VideoWriter after completion.

import numpy as np
import cv2

cap = cv2.VideoCapture(1)

fourcc = cv2.cv.CV_FOURCC('X','V','I','D')
out = cv2.VideoWriter('output.avi', fourcc, 20.0,(640,480))

while(True):
    ret, frame = cap.read()
    if cap.isOpened() == 0:
        cap.open(1)

    if ret==True:

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        out.write(gray)
        cv2.imshow('frame',gray)

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

    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()
1
  • I'm sad to see no answers here, as I'm now having the same problem. :-( Commented Jan 23, 2015 at 23:56

2 Answers 2

0

Instead of using the lines below:

fourcc = cv2.cv.CV_FOURCC('X','V','I','D')
out = cv2.VideoWriter('output.avi', fourcc, 20.0,(640,480))

Use those one:

fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (int(cap.get(3)),int(cap.get(4))))

I think, this will help you.

Sign up to request clarification or add additional context in comments.

Comments

-1

Instead of using this line

fourcc = cv2.cv.CV_FOURCC('X','V','I','D')

Use this one

fourcc = cv2.VideoWriter_fourcc(*'XVID')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.