之前的博文中我们和大家讲过EasyNVR的录像计划的实现方式,大家可以简单了解一下操作方式:EasyNVR边缘计算网关录像计划功能操作介绍。关于EasyNVR录像计划的实现,TSINGSEE青犀视频的研发人员也耗费了不少心思,下面我们就讲一下是是如何实现的。
EasyNVR录像计划,其实就是在EasyNVR先为通道配置好录像计划,然后该通道就会以录像计划中的计划设置来录像。例如:通道1只开启每天的下午1点到2点录像,那么通道1就只会在每天的下午1点到2点有录像,不会像现在一旦开启录像,就是直接录像一整天。
这样就可以达到节省磁盘空间的效果,录像也更灵活。下面是实现代码:
代码语言:javascript复制func checkRecordPlan() gin.HandlerFunc {
return func(c *gin.Context) {
c.Request.ParseForm()
log.Printf("----------form:%s", c.Request.Form)
app := c.Request.Form.Get("app")
call := c.Request.Form.Get("call")
name := c.Request.Form.Get("name")
channelId, _ := strconv.Atoi(name[7:])
if app == "record" && (call == "update_publish" || call == "publish") {
var camera models.Camera
models.DB.Model(models.Camera{}).Where("id = ?", channelId).First(&camera)
recordDay, _ := strconv.Atoi(camera.Reserve3)
if recordDay != 0 {
log.Printf("----------RecordAllPlan:%s", camera.RecordAllPlan)
if camera.RecordPlanEnable == 0 && camera.RecordAllPlan != "" {
if !checkTimeByRecordPlan(camera.RecordAllPlan) {
channelInfo := channels.GetChannel(uint(channelId))
channelInfo.StopRecordPusher()
c.AbortWithStatus(http.StatusBadRequest)
return
}
}
//{"Monday":"","Tuesday":"15:50:00-16:00:00","Wednesday":"","Thursday":"","Friday":"","Saturday":"","Sunday":""}
if camera.RecordPlanEnable == 1 && camera.RecordPlan != "" {
if !checkTimeByRecordPlan(camera.RecordPlan) {
channelInfo := channels.GetChannel(uint(channelId))
channelInfo.StopRecordPusher()
c.AbortWithStatus(http.StatusBadRequest)
return
}
}
}
}
c.Next()
}
}
func CheckTimeUnix(timeArr []string) bool {
if timeArr[0] == "" {
return false
}
stampStart, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02") " " timeArr[0], time.Local)
stampEnd, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02") " " timeArr[1], time.Local)
stampNow := time.Now().Unix()
if stampNow >= stampStart.Unix() && stampNow <= stampEnd.Unix() {
return true
}
return false
}
其实就是靠一个字段来判断何时可以录像。
举个例子:
{“Monday”:"",“Tuesday”:“15:00:00-16:00:00”,“Wednesday”:"",“Thursday”:"",“Friday”:"",“Saturday”:"",“Sunday”:""}
比如上面的这一个字符串,意思就是只会在星期2的下午3点到下午4点录像,其他时间段不录像。
如果大家还想了解EasyNVR更多相关内容,可以自行下载测试,EasyNVR测试版本均提供API接口可进行二次开发,与正式版本无异,如若还有视频相关解决方案上的疑问,欢迎联系我们。