Reputation: 145
import cv
import cv2
cap = cv2.VideoCapture(0)
cap.set(8,100)
out = cv2.VideoWriter('/home/pi/Desktop/output.mp4',cv2.cv.CV_FOURCC('D','I','V','X'),20.0,(640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(10) == 27:
break
cv2.VideoCapture(0).release()
out.release()
cv2.destroyAllWindows()
This code worked but it never stopped and no video file had been saved. Does anyone know how to solve this? Thanks a lot.
Upvotes: 0
Views: 2317
Reputation: 11232
Both release() calls can be removed.
cv2.VideoCapture(0).release()
would call release() on a new VideoCapture, what you meant was cap.release()
.
For the VideoWriter, the release method doesn't exist - you don't have to care about releasing the VideoWriter or VideoCapture in Python. They will be released when their object is destroyed at the end of your program.
Upvotes: 2