mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-12-24 13:48:04 +08:00
fix: 1.hls record failed;2.mp4 record filename use mileseconds;3.gb28181 update channels
This commit is contained in:
@@ -230,6 +230,7 @@ func (c *catalogHandlerTask) Run() (err error) {
|
||||
c.CustomChannelId = c.ChannelId
|
||||
}
|
||||
// 使用 Save 进行 upsert 操作
|
||||
d.Debug("ready to addOrUpdateChannel", "channel.ID is", c.ID, "channel.Status is", c.Status)
|
||||
d.addOrUpdateChannel(c)
|
||||
catalogReq.TotalCount++
|
||||
}
|
||||
@@ -631,7 +632,8 @@ func (d *Device) frontEndCmdString(cmdCode int32, parameter1 int32, parameter2 i
|
||||
}
|
||||
|
||||
func (d *Device) addOrUpdateChannel(c gb28181.DeviceChannel) {
|
||||
if channel, ok := d.channels.Get(c.ID); ok {
|
||||
var resultChannel *Channel
|
||||
if channel, ok := d.plugin.channels.Get(c.ID); ok {
|
||||
// 通道已存在,保留自定义字段
|
||||
if channel.DeviceChannel != nil {
|
||||
// 保存原有的自定义字段
|
||||
@@ -648,16 +650,18 @@ func (d *Device) addOrUpdateChannel(c gb28181.DeviceChannel) {
|
||||
}
|
||||
// 更新通道信息
|
||||
channel.DeviceChannel = &c
|
||||
resultChannel = channel
|
||||
d.Debug("addOrUpdateChannel, get channel from d.plugin.channels", "channel.ID is ", c.ID, "channel.Status is", c.Status)
|
||||
} else {
|
||||
// 创建新通道
|
||||
channel = &Channel{
|
||||
resultChannel = &Channel{
|
||||
Device: d,
|
||||
Logger: d.Logger.With("channel", c.ID),
|
||||
DeviceChannel: &c,
|
||||
}
|
||||
d.channels.Set(channel)
|
||||
d.plugin.channels.Set(channel)
|
||||
}
|
||||
d.channels.Set(resultChannel)
|
||||
d.plugin.channels.Set(resultChannel)
|
||||
}
|
||||
|
||||
func (d *Device) GetID() string {
|
||||
|
||||
@@ -54,6 +54,11 @@ func (w *HLSWriter) GetTs(key string) (any, bool) {
|
||||
}
|
||||
|
||||
func (w *HLSWriter) checkNoBodyRead() bool {
|
||||
// 如果从未被读取过(纯录制模式),不检查超时
|
||||
if w.lastReadTime.IsZero() {
|
||||
return false
|
||||
}
|
||||
// 曾经有人播放过,检查是否15秒无访问
|
||||
return time.Since(w.lastReadTime) > time.Second*15
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,10 @@ var CustomFileName = func(job *m7s.RecordJob) string {
|
||||
if job.RecConf.Fragment == 0 {
|
||||
return fmt.Sprintf("%s.mp4", job.RecConf.FilePath)
|
||||
}
|
||||
return filepath.Join(job.RecConf.FilePath, fmt.Sprintf("%d.mp4", time.Now().Unix()))
|
||||
// 使用纳秒级时间戳,避免同一秒内多次切片时文件名冲突
|
||||
// 格式:秒_纳秒.mp4 (例如: 1760431346_123456789.mp4)
|
||||
now := time.Now()
|
||||
return filepath.Join(job.RecConf.FilePath, fmt.Sprintf("%d_%09d.mp4", now.Unix(), now.Nanosecond()))
|
||||
}
|
||||
|
||||
func (r *Recorder) createStream(start time.Time) (err error) {
|
||||
|
||||
Reference in New Issue
Block a user