[英]Save Cv2 video file to another location
我有一个使用 python 在后台录制网络摄像头的脚本,但我想将剪辑保存到特定目录,我想知道是否有任何方法可以做到这一点
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()
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()
如果有疑问,可以参考文档。
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.