mirror of
https://github.com/kerberos-io/agent.git
synced 2026-10-19 17:38:25 +00:00
Add GOP size configuration and enhance pre-recording handling for improved stream management
This commit is contained in:
@@ -660,7 +660,10 @@ func (g *Golibrtsp) Start(ctx context.Context, streamType string, queue *packets
|
||||
g.Streams[g.VideoH264Index].GopSize = gopSize
|
||||
log.Log.Info(fmt.Sprintf("capture.golibrtsp.Start(%s): Keyframe interval=%d packets, Avg=%.1f, GOP=%.1fs, GOPSize=%d",
|
||||
streamType, keyframeInterval, avgInterval, gopDuration, gopSize))
|
||||
queue.SetMaxGopCount(gopSize)
|
||||
preRecording := configuration.Config.Capture.PreRecording
|
||||
if preRecording > 0 && int(gopDuration) > 0 {
|
||||
queue.SetMaxGopCount(int(preRecording) / int(gopDuration))
|
||||
}
|
||||
}
|
||||
|
||||
pkt.Data = pkt.Data[4:]
|
||||
@@ -801,7 +804,8 @@ func (g *Golibrtsp) Start(ctx context.Context, streamType string, queue *packets
|
||||
g.Streams[g.VideoH265Index].GopSize = gopSize
|
||||
log.Log.Info(fmt.Sprintf("capture.golibrtsp.Start(%s): Keyframe interval=%d packets, Avg=%.1f, GOP=%.1fs, GOPSize=%d",
|
||||
streamType, keyframeInterval, avgInterval, gopDuration, gopSize))
|
||||
queue.SetMaxGopCount(gopSize)
|
||||
preRecording := configuration.Config.Capture.PreRecording
|
||||
queue.SetMaxGopCount(int(preRecording) / int(gopDuration))
|
||||
}
|
||||
|
||||
queue.WritePacket(pkt)
|
||||
|
||||
@@ -419,9 +419,21 @@ func HandleRecordStream(queue *packets.Queue, configDirectory string, configurat
|
||||
// Taking into account FPS = GOP size (Keyfram interval)
|
||||
if preRecording > 0 {
|
||||
|
||||
gopRatio := int64(2) //configuration.Config.Capture.IPCamera.GOPSize
|
||||
displayTime = startRecording - preRecording/gopRatio - 500*gopRatio
|
||||
fmt.Println(lastRecordingTime)
|
||||
streams, _ := rtspClient.GetStreams()
|
||||
videoIdx := -1
|
||||
audioIdx := -1
|
||||
for i, stream := range streams {
|
||||
if (stream.Name == "H264" || stream.Name == "H265") && videoIdx < 0 {
|
||||
videoIdx = i
|
||||
} else if stream.Name == "PCM_MULAW" && audioIdx < 0 {
|
||||
audioIdx = i
|
||||
}
|
||||
}
|
||||
//videoStream := streams[videoIdx]
|
||||
//gopSize := videoStream.GopSize
|
||||
//fps := videoStream.FPS
|
||||
displayTime = startRecording //*(int64(gopSize)/int64(fps)) // we substract the pre-recording time in milliseconds, divided by the gop size and fps.
|
||||
fmt.Println(lastRecordingTime, startRecording, preRecording, displayTime)
|
||||
|
||||
// Might be that recordings are coming short after each other.
|
||||
// Therefore we do some math with the current time and the last recording time.
|
||||
@@ -498,7 +510,7 @@ func HandleRecordStream(queue *packets.Queue, configDirectory string, configurat
|
||||
var cursorError error
|
||||
var pkt packets.Packet
|
||||
var nextPkt packets.Packet
|
||||
recordingCursor := queue.DelayedGopCount(int(config.Capture.PreRecording + 1))
|
||||
recordingCursor := queue.Oldest()
|
||||
|
||||
if cursorError == nil {
|
||||
pkt, cursorError = recordingCursor.ReadPacket()
|
||||
|
||||
@@ -254,7 +254,7 @@ func RunAgent(configDirectory string, configuration *models.Configuration, commu
|
||||
if subStreamEnabled && rtspSubClient != nil {
|
||||
subQueue = packets.NewQueue()
|
||||
communication.SubQueue = subQueue
|
||||
subQueue.SetMaxGopCount(3) // GOP time frame is set to prerecording (we'll add 2 gops to leave some room).
|
||||
subQueue.SetMaxGopCount(3) // GOP time frame is set to 3 for motion detection and livestreaming.
|
||||
subQueue.WriteHeader(videoSubStreams)
|
||||
go rtspSubClient.Start(ctx, "sub", subQueue, configuration, communication)
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ type Capture struct {
|
||||
Continuous string `json:"continuous,omitempty"`
|
||||
PostRecording int64 `json:"postrecording"`
|
||||
PreRecording int64 `json:"prerecording"`
|
||||
GopSize int `json:"gopsize,omitempty" bson:"gopsize,omitempty"` // GOP size in seconds, used for pre-recording
|
||||
MaxLengthRecording int64 `json:"maxlengthrecording"`
|
||||
TranscodingWebRTC string `json:"transcodingwebrtc"`
|
||||
TranscodingResolution int64 `json:"transcodingresolution"`
|
||||
|
||||
Reference in New Issue
Block a user