import cv2
import sys
import time
dt = "2019-01-23 15:29:00"
#转换成时间数组
timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
#转换成时间戳
timestamp = time.mktime(timeArray)
print(timeArray)
print(timestamp)
cap_1 = cv2.VideoCapture(1)
cap_1.set(3,1920)
cap_1.set(4,1080)
# cap_2 = cv2.VideoCapture(2)
# cap_3 = cv2.VideoCapture(3)
# cap_4 = cv2.VideoCapture(4)
write_ok = False
sz = (int(cap_1.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(cap_1.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fps = 30
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
# fourcc = cv2.VideoWriter_fourcc(*'mpeg')
vout_1 = cv2.VideoWriter()
vout_1.open('./1/output.mp4',fourcc,fps,sz,True)
# vout_2 = cv2.VideoWriter()
# vout_2.open('./2/output.mp4',fourcc,fps,sz,True)
# vout_3 = cv2.VideoWriter()
# vout_3.open('./3/output.mp4',fourcc,fps,sz,True)
cnt = 0
while(True):
if(write_ok):
# print("video")
#获取当前时间
time_now = int(time.time())
#转换成localtime
# time_local = time.localtime(time_now)
print(time_now)
if time_now >= timestamp:
while(cnt < 900):
cnt += 1
print(cnt)
ret_1, frame_1 = cap_1.read()
vout_1.write(frame_1)
# ret_2, frame_2 = cap_2.read()
# vout_2.write(frame_2)
# ret_3, frame_3 = cap_3.read()
# vout_3.write(frame_3)
vout_1.release()
# vout_2.release()
# vout_3.release()
sys.exit()
else:
print("stop")
ret_1, frame_1 = cap_1.read()
cv2.imshow("cam_1", frame_1)
# ret_2, frame_2 = cap_2.read()
# cv2.imshow("cam_2", frame_2)
# ret_3, frame_3 = cap_3.read()
# cv2.imshow("cam_3", frame_3)
if cv2.waitKey(1) & 0xFF==ord("w"):
write_ok = write_ok is not True
python-opencv 读取摄像头并保存为.mp4视频
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 一、实例代码 二、一些补充 在上述代码中,已经对内容进行了详细的注释,仔细阅读应该可以轻松掌握。在此处只对一些属性...
- 背景 如果你关注过一些关于黑客的新闻,应该了解,有些黑客会悄悄打开你电脑的摄像头,然后监控你的一举一动,更有甚者,...
- 准备写个pyqt5显示摄像头,百度一看,居然全是要csdn下载的!!!!于是我很伤心,人与人之间基本的信任都没有了...