增加分片录制能力以及hls录制能力

This commit is contained in:
dexter
2022-05-26 11:29:24 +08:00
parent 48d7f1a65b
commit da81af3bf9
9 changed files with 417 additions and 149 deletions

43
subscriber.go Normal file
View 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)
}
}