直接上代码
参考:
原文链接:https://blog.csdn.net/qq_39734584/article/details/90417597
原文链接:https://blog.csdn.net/xwm1000/article/details/71788344
# coding:utf-8
import cv2
import sys
cap = cv2.VideoCapture(0)
fps=cap.get(cv2.CAP_PROP_FPS) #获取帧率
width=int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) #一定要转int 否则是浮点数
height=int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
size=(width,height) #大小
fourcc = cv2.VideoWriter_fourcc('m','p','4','v') # cv2.VideoWriter_fourcc('m','p','4','v')
out = cv2.VideoWriter('./output.mp4', fourcc, fps, size)
while True:
ret,frame = cap.read()
if ret == True:
frame = cv2.flip(frame, 1)
a = out.write(frame)
cv2.imshow("video", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()