Reputation: 11
I have a script that record the webcam in the background using python, but I want to save the clip to a specific directory, I was wondering if there's any way that I could do that
import cv2
cam = cv2.VideoCapture(0) # Começa a gravar
out = cv2.VideoWriter('Teste.avi', -1, 20.0, (640, 480))
if cam.isOpened(): # Camera on ou não
op, frame = cam.read()
else:
op = False
while op:
if cv2.waitKey(1) == ord('x'): # Para o programa
break
cam.release()
Upvotes: 1
Views: 961
Reputation: 41
import os
your_path = "location where you want to save"
try:
os.mkdir(your_path)
except:
pass #directory already there
out = cv2.VideoWriter(your_path+'/output.avi',fourcc, 20.0, (640,480))
Upvotes: 1
Reputation: 1994
import cv2
cam = cv2.VideoCapture(0) # Começa a gravar
# out = cv2.VideoWriter('Teste.avi', -1, 20.0, (640, 480))
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('path//of//location//output.avi',fourcc, 20.0, (640,480))
while (cam.isOpened()):
op,frame = cam.read()
if (op == True):
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('x'):
break
else:
break
cam.release()
out.release()
cv2.destroyAllWindows()
If you have any doubt, you can refer to the documentation.
Upvotes: 1