mirror of
https://github.com/Monibuca/plugin-record.git
synced 2025-10-05 08:46:59 +08:00
增加视频裸流录制功能
This commit is contained in:
46
raw.go
Normal file
46
raw.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
. "m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/codec"
|
||||
"m7s.live/engine/v4/track"
|
||||
)
|
||||
|
||||
type RawRecorder struct {
|
||||
Recorder
|
||||
}
|
||||
|
||||
func (r *RawRecorder) OnEvent(event any) {
|
||||
r.Recorder.OnEvent(event)
|
||||
switch v := event.(type) {
|
||||
case *track.Video:
|
||||
if r.Ext == "." {
|
||||
if v.CodecID == codec.CodecID_H264 {
|
||||
r.Ext = ".h264"
|
||||
} else {
|
||||
r.Ext = ".h265"
|
||||
}
|
||||
}
|
||||
case VideoDeConf:
|
||||
annexB := v.GetAnnexB()
|
||||
annexB.WriteTo(r)
|
||||
case *VideoFrame:
|
||||
if r.Fragment != 0 && r.newFile {
|
||||
r.newFile = false
|
||||
r.Close()
|
||||
if file, err := r.CreateFileFn(filepath.Join(r.Stream.Path, strconv.FormatInt(time.Now().Unix(), 10)+r.Ext), false); err == nil {
|
||||
r.SetIO(file)
|
||||
if r.Video.Track != nil {
|
||||
annexB := VideoDeConf(r.Video.Track.DecoderConfiguration).GetAnnexB()
|
||||
annexB.WriteTo(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
annexB := v.GetAnnexB()
|
||||
annexB.WriteTo(r)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user