mirror of
https://github.com/Monibuca/plugin-record.git
synced 2025-10-05 16:56:53 +08:00
增加文件抽象和文件流过滤
This commit is contained in:
10
flv.go
10
flv.go
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/Monibuca/utils/v3/codec"
|
||||
)
|
||||
|
||||
func getDuration(file *os.File) uint32 {
|
||||
func getDuration(file FileWr) uint32 {
|
||||
_, err := file.Seek(-4, io.SeekEnd)
|
||||
if err == nil {
|
||||
var tagSize uint32
|
||||
@@ -34,13 +34,19 @@ func SaveFlv(streamPath string, append bool) error {
|
||||
flag = flag | os.O_TRUNC | os.O_WRONLY
|
||||
}
|
||||
filePath := filepath.Join(config.Path, streamPath+".flv")
|
||||
var file FileWr
|
||||
var err error
|
||||
if ExtraConfig.CreateFileFn == nil {
|
||||
if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := os.OpenFile(filePath, flag, 0755)
|
||||
file, err = os.OpenFile(filePath, flag, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}else {
|
||||
file,err = ExtraConfig.CreateFileFn(filePath)
|
||||
}
|
||||
// return avformat.WriteFLVTag(file, packet)
|
||||
p := Subscriber{
|
||||
ID: filePath,
|
||||
|
15
main.go
15
main.go
@@ -2,6 +2,7 @@ package record
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@@ -25,6 +26,18 @@ type FlvFileInfo struct {
|
||||
Duration uint32
|
||||
}
|
||||
|
||||
type FileWr interface {
|
||||
io.Reader
|
||||
io.Writer
|
||||
io.Seeker
|
||||
io.Closer
|
||||
}
|
||||
|
||||
var ExtraConfig struct {
|
||||
CreateFileFn func(filename string) (FileWr,error)
|
||||
AutoRecordFilter func(stream string) bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
InstallPlugin(&PluginConfig{
|
||||
Name: "Record",
|
||||
@@ -115,7 +128,7 @@ func run() {
|
||||
|
||||
func onPublish(v interface{}) {
|
||||
p := v.(*Stream)
|
||||
if config.AutoRecord {
|
||||
if config.AutoRecord || (ExtraConfig.AutoRecordFilter != nil && ExtraConfig.AutoRecordFilter(p.StreamPath)) {
|
||||
SaveFlv(p.StreamPath, false)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user