mirror of
https://github.com/Monibuca/plugin-record.git
synced 2025-10-17 06:10:36 +08:00
增加分片录制能力以及hls录制能力
This commit is contained in:
43
subscriber.go
Normal file
43
subscriber.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
. "m7s.live/engine/v4"
|
||||
)
|
||||
|
||||
type Recorder struct {
|
||||
Subscriber
|
||||
*Record
|
||||
newFile bool // 创建了新的文件
|
||||
append bool // 是否追加模式
|
||||
}
|
||||
|
||||
func (r *Recorder) OnEvent(event any) {
|
||||
switch v := event.(type) {
|
||||
case ISubscriber:
|
||||
filename := strconv.FormatInt(time.Now().Unix(), 10) + r.Ext
|
||||
if r.Fragment == 0 {
|
||||
filename = r.Stream.Path + r.Ext
|
||||
} else {
|
||||
filename = filepath.Join(r.Stream.Path, filename)
|
||||
}
|
||||
if file, err := r.CreateFileFn(filename, r.append); err == nil {
|
||||
r.SetIO(file)
|
||||
go func() {
|
||||
r.PlayBlock()
|
||||
recordConfig.recordings.Delete(r.ID)
|
||||
r.Close()
|
||||
}()
|
||||
}
|
||||
case *VideoFrame:
|
||||
if ts := v.AbsTime; v.IFrame && int64(ts-r.Video.First.AbsTime) >= int64(r.Fragment*1000) {
|
||||
r.Video.First.AbsTime = ts
|
||||
r.newFile = true
|
||||
}
|
||||
default:
|
||||
r.Subscriber.OnEvent(event)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user