视频存储
程序员文章站
2024-01-17 13:34:10
判断存储的视频时长是否合理import time, datetimeimport configDB as configDBimport cv2def video_test(ip, stratTime, endTime,file_path): #获取数据库连接 mysql = configDB.MyPymysqlPool("dbMysql") cap = cv2.VideoCapture(file_path) if cap.isOpened(): # 当成功打开视...
判断存储的视频时长是否合理
import time, datetime
import configDB as configDB
import cv2
def video_test(ip, stratTime, endTime,file_path):
#获取数据库连接
mysql = configDB.MyPymysqlPool("dbMysql")
cap = cv2.VideoCapture(file_path)
if cap.isOpened(): # 当成功打开视频时cap.isOpened()返回True,否则返回False
VideoTime = cap.get(7) / cap.get(5)
print(VideoTime)
#获取当前时间
timeNow = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
#获取数据库中存入的视频开始结束时间
stratTimeSec = StrToSecond(stratTime)
endTimeSec = StrToSecond(endTime)
#程序运行时间
pro_video_time = (endTimeSec-stratTimeSec)
#判断时间差是否合理,根据两者之间时间差,如果差距较大,向数据库alert表插入一条告警数据
if VideoTime-pro_video_time>60 or VideoTime-pro_video_time<-60:
#通过IP获取当前摄像机编号
sql = "select crccid from camera where ip=ip"
crccid = mysql.getAll(sql)[0]['crccid']
sql = "insert into alert (ts,source,code,detail) values (%s,%s,%s,%s)"
params = [timeNow, crccid, '00101', '视频丢失']
try:
mysql.insert(sql, params)
mysql.end()
print("告警成功")
except Exception as e:
print("==============>",e)
else:
print("合理")
def StrToSecond(strtime):
DateTime = datetime.datetime.strptime(strtime, '%Y-%m-%d %H:%M:%S')
return time.mktime(DateTime.timetuple())
- 主要用来判断当前摄像机录入的视频是否完整,如果完整则不作处理,如果不完整,向alert表中插入一条告警数据。
本文地址:https://blog.csdn.net/aaxinger/article/details/108993153
上一篇: MongoDB教程之入门基础知识
下一篇: Ajax post请求跳转页面