How to correspond with the warning information and warning video of the EasyGBS streaming media video platform with the GB28181 protocol?

In the previous blog post, we mentioned that the EasyGBS video platform has developed an alarm function . When an abnormal situation is detected, the system will automatically take a snapshot and record the time. However, before this function was actually launched, some problems were encountered, such as the situation where the video and the alarm record did not match when the alarm was intercepted. Today I will share with you the solutions to problems in the development process.

Because the alarm information is real-time, and the video needs the EasyGBS platform to save. The access video is saved 20 seconds after the alarm information comes. At this time, there will be a time difference between the saved video and the alarm record. In this time difference, new alarm information may be generated, so the alarm record and the video will have a deviation .

How to avoid this deviation? We have chosen the method of assigning an identification to the alarm video, that is, when adding the storage alarm video, pass in the id of the alarm record, and associate the alarm video with the alarm record one by one. The following is the reference code:

modelsAlarm := &models.Alarm{
			DeviceID:      serial,
			ChannelID:     deviceId,
			DeviceName:    device.Name,
			ChannelName:   channels.Name,
			AlarmPriority: alarmPriority,
			AlarmTime:     aTime,
			AlarmMethod:   alarmMethod,
			AlarmType:     alarmType,
			AlarmSnap:     "",
		}

		db.SQLite.Create(modelsAlarm)
		fmt.Println(modelsAlarm.ID)
		go doAlarmSnap(c, *channels, serial, modelsAlarm.ID)

Then add alarm id information to the saved video file name.

alarmRecordKey := fmt.Sprintf("alarm_record_%s_%s", msess.GetDeviceID(), msess.GetChannelID())
   			alarmRecordURL := fmt.Sprintf("/alarmrecords/alarm_%d_record_%s_%s.mp4", msess.AlarmID, msess.GetDeviceID(), msess.GetChannelID())
   			oldFileName := fmt.Sprintf("alarm_%d_record_%s_%s.h264", msess.AlarmID, msess.GetDeviceID(), msess.GetChannelID())
   			newFileName := fmt.Sprintf("alarm_%d_record_%s_%s.mp4", msess.AlarmID, msess.GetDeviceID(), msess.GetChannelID())
   			var alarmRecord = redis.Client.Get(alarmRecordKey).Val()
   			if alarmRecord != "" {
   				inFile := filepath.Join(utils.DataDir(), "alarmrecords", oldFileName)
   				outFile := filepath.Join(utils.DataDir(), "alarmrecords", newFileName)
   				if _, err := os.Stat(inFile); os.IsNotExist(err) {
   					sms_log.Log.Printf("alarm record h264 to mp4 error, %v", err)
   				}
   				ff.H264ToMP4(inFile, outFile)
   				redis.Client.Del(alarmRecordKey)
   				err := models.UpdateAlarmRecord(msess.AlarmID, alarmRecordURL)
   				if err != nil {
   					sms_log.Log.Printf("alarm record end error, %v", err)
   				}
   				msess.AlarmID = 0
   				if err := os.Remove(inFile); err != nil {
   					log.Println(err)
   				}

After the above two pieces of code are added, the saved video file information carries the alarm id, which can correspond to the alarm record.

The development of the alarm function is not only to allow operation and maintenance personnel to understand important alarms in the first time, but also to bring a new direction to the development of alarm linkage. After the alarm system is triggered, the alarm host sends a signal to the linkage module. Turn on the monitoring equipment and searchlight, and connect the monitoring equipment to the AI ​​(analog input) or DI (switch input) channel of the monitoring host. Once the monitoring host receives the alarm signal from the monitoring equipment (the mechanism of analog alarm is that the voltage exceeds the preset setting The set threshold range generates an alarm.

In the later stage, the R&D team of TSINGSEE Qingxi Video will also improve the alarm linkage function of the EasyGBS video platform of the national standard GB28181 video platform, and optimize the EasyGBS function.

EasyDarwin is an open source community developed and maintained by the domestic video streaming team TSINGSEE Qingxi Video. Since its creation and development in December 2012, it has expanded from the original single-service streaming media server form to the current open source project of the cloud platform architecture.

Guess you like

Origin blog.csdn.net/EasyGBS/article/details/108753049