record

package module
v4.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 30 Imported by: 0

README

RECORD插件

对流进行录制的功能插件,提供Flv、fmp4、hls、裸流格式的录制功能。

插件地址

https://github.com/Monibuca/plugin-record

插件引入

import (
    _ "m7s.live/plugin/record/v4"
)

配置

  • 配置中的path 表示要保存的文件的根路径,可以使用相对路径或者绝对路径
  • filter 代表要过滤的StreamPath正则表达式,如果不匹配,则表示不录制。为空代表不进行过滤
  • fragment表示分片大小(20s代表20秒,1m代表1分钟,可以组合),0代表不分片
record:
  subscribe: # 参考全局配置格式
  flv:
      ext: .flv
      path: record/flv
      autorecord: false
      filter: ""
      fragment: 0
  mp4:
      ext: .mp4
      path: record/mp4
      autorecord: false
      filter: ""
      fragment: 0
  hls:
      ext: .m3u8
      path: record/hls
      autorecord: false
      filter: ""
      fragment: 0
  raw:
      ext: .
      path: record/raw
      autorecord: false
      filter: ""
      fragment: 0

API

  • /record/api/list/recording 罗列所有正在录制中的流的信息
  • /record/api/list?type=[flv|mp4|hls|raw] 罗列所有录制的flv|mp4|m3u8|raw文件
  • /record/api/start?type=flv&streamPath=live/rtc&fileName=xxx&fragment=10s 开始录制某个流,返回一个字符串用于停止录制用的id(fileName是可选的,且只用于非切片情况,fragment用于覆盖配置中的切片时间,是可选的,如果fileName和fragment都存在,则忽略fileName)
  • /record/api/stop?id=xxx 停止录制某个流

点播功能

访问格式: [http/https]://[host]:[port]/record/[streamPath].[flv|mp4|m3u8|h264|h265]

例如:

  • http://localhost:8080/record/live/test.flv 将会读取对应的flv文件
  • http://localhost:8080/record/live/test.mp4 将会读取对应的fmp4文件

// GO仓库刷新INDEX

GOPROXY=proxy.golang.org go list -m github.com/eanfs/plugin-record/v4@v4.6.5

GOPROXY=proxy.golang.org go list -m github.com/eanfs/plugin-transform/v1@v1.0.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordExist = errors.New("recorder exist")
View Source
var RecordPluginConfig = &RecordConfig{
	Flv: Record{
		Path:          "record/flv",
		Ext:           ".flv",
		GetDurationFn: getFLVDuration,
	},
	Fmp4: Record{
		Path: "record/fmp4",
		Ext:  ".mp4",
	},
	Mp4: Record{
		Path: "record/mp4",
		Ext:  ".mp4",
	},
	Hls: Record{
		Path: "record/hls",
		Ext:  ".m3u8",
	},
	Raw: Record{
		Path: "record/raw",
		Ext:  ".",
	},
	RawAudio: Record{
		Path: "record/raw",
		Ext:  ".",
	},
}
View Source
var WritingFiles sync.Map

Functions

This section is empty.

Types

type FLVRecorder

type FLVRecorder struct {
	Recorder

	Offset int64
	// contains filtered or unexported fields
}

func NewFLVRecorder

func NewFLVRecorder() (r *FLVRecorder)

func (*FLVRecorder) Close

func (r *FLVRecorder) Close() (err error)

func (*FLVRecorder) OnEvent

func (r *FLVRecorder) OnEvent(event any)

func (*FLVRecorder) Start

func (r *FLVRecorder) Start(streamPath string) (err error)

func (*FLVRecorder) StartWithFileName added in v4.6.0

func (r *FLVRecorder) StartWithFileName(streamPath string, fileName string) error

type FMP4Recorder

type FMP4Recorder struct {
	Recorder
	// contains filtered or unexported fields
}

func NewFMP4Recorder

func NewFMP4Recorder() *FMP4Recorder

func (*FMP4Recorder) Close

func (r *FMP4Recorder) Close() (err error)

func (*FMP4Recorder) OnEvent

func (r *FMP4Recorder) OnEvent(event any)

func (*FMP4Recorder) Start

func (r *FMP4Recorder) Start(streamPath string) (err error)

func (*FMP4Recorder) StartWithFileName added in v4.6.0

func (r *FMP4Recorder) StartWithFileName(streamPath string, fileName string) error

type FileWr

type FileWr interface {
	io.Reader
	io.Writer
	io.Seeker
	io.Closer
}

type FileWriter

type FileWriter struct {
	io.Reader
	io.Writer
	io.Seeker
	io.Closer
	// contains filtered or unexported fields
}

func (*FileWriter) Close

func (f *FileWriter) Close() error

func (*FileWriter) Seek

func (f *FileWriter) Seek(offset int64, whence int) (int64, error)

type HLSRecorder

type HLSRecorder struct {
	Recorder
	MemoryTs
	// contains filtered or unexported fields
}

func NewHLSRecorder

func NewHLSRecorder() (r *HLSRecorder)

func (*HLSRecorder) Close

func (r *HLSRecorder) Close() (err error)

func (*HLSRecorder) CreateFile

func (h *HLSRecorder) CreateFile() (fw FileWr, err error)

创建一个新的ts文件

func (*HLSRecorder) OnEvent

func (h *HLSRecorder) OnEvent(event any)

func (*HLSRecorder) Start

func (h *HLSRecorder) Start(streamPath string) error

func (*HLSRecorder) StartWithFileName added in v4.6.0

func (h *HLSRecorder) StartWithFileName(streamPath string, fileName string) error

type IRecorder

type IRecorder interface {
	ISubscriber
	GetRecorder() *Recorder
	Start(streamPath string) error
	StartWithFileName(streamPath string, fileName string) error
	io.Closer
	CreateFile() (FileWr, error)
}

type MP4Recorder

type MP4Recorder struct {
	Recorder
	*mp4.Movmuxer `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

func NewMP4Recorder

func NewMP4Recorder() *MP4Recorder

func (*MP4Recorder) Close

func (r *MP4Recorder) Close() (err error)

func (*MP4Recorder) OnEvent

func (r *MP4Recorder) OnEvent(event any)

func (*MP4Recorder) Start

func (r *MP4Recorder) Start(streamPath string) (err error)

func (*MP4Recorder) StartWithFileName added in v4.6.0

func (r *MP4Recorder) StartWithFileName(streamPath string, fileName string) error

type RawRecorder

type RawRecorder struct {
	Recorder
	IsAudio bool
}

func NewRawAudioRecorder

func NewRawAudioRecorder() (r *RawRecorder)

func NewRawRecorder

func NewRawRecorder() (r *RawRecorder)

func (*RawRecorder) Close

func (r *RawRecorder) Close() (err error)

func (*RawRecorder) OnEvent

func (r *RawRecorder) OnEvent(event any)

func (*RawRecorder) Start

func (r *RawRecorder) Start(streamPath string) error

func (*RawRecorder) StartWithFileName added in v4.6.0

func (r *RawRecorder) StartWithFileName(streamPath string, fileName string) error

type Record

type Record struct {
	Ext           string        `desc:"文件扩展名"`           //文件扩展名
	Path          string        `desc:"存储文件的目录"`         //存储文件的目录
	AutoRecord    bool          `desc:"是否自动录制"`          //是否自动录制
	Filter        config.Regexp `desc:"录制过滤器"`           //录制过滤器
	Fragment      time.Duration `desc:"分片大小,0表示不分片"`     //分片大小,0表示不分片
	Duration      time.Duration `desc:"视频最大录制时长,0表示不限制"` //分片大小,0表示不分片
	http.Handler  `json:"-" yaml:"-"`
	CreateFileFn  func(filename string, append bool) (FileWr, error) `json:"-" yaml:"-"`
	GetDurationFn func(file io.ReadSeeker) uint32                    `json:"-" yaml:"-"`
}

func (*Record) Init

func (r *Record) Init()

func (*Record) NeedRecord

func (r *Record) NeedRecord(streamPath string) bool

func (*Record) Tree

func (r *Record) Tree(dstPath string, level int) (files []*VideoFileInfo, err error)

type RecordConfig

type RecordConfig struct {
	config.Subscribe
	Flv      Record `desc:"flv录制配置"`
	Mp4      Record `desc:"mp4录制配置"`
	Fmp4     Record `desc:"fmp4录制配置"`
	Hls      Record `desc:"hls录制配置"`
	Raw      Record `desc:"视频裸流录制配置"`
	RawAudio Record `desc:"音频裸流录制配置"`

	Storage StorageConfig `desc:"MINIO 配置"`
	// contains filtered or unexported fields
}

func (*RecordConfig) API_list

func (conf *RecordConfig) API_list(w http.ResponseWriter, r *http.Request)

func (*RecordConfig) API_list_page added in v4.6.0

func (conf *RecordConfig) API_list_page(w http.ResponseWriter, r *http.Request)

func (*RecordConfig) API_list_recording

func (conf *RecordConfig) API_list_recording(w http.ResponseWriter, r *http.Request)

func (*RecordConfig) API_list_recording_page added in v4.6.0

func (conf *RecordConfig) API_list_recording_page(w http.ResponseWriter, r *http.Request)

func (*RecordConfig) API_recordfile_delete added in v4.6.0

func (conf *RecordConfig) API_recordfile_delete(w http.ResponseWriter, r *http.Request)

func (*RecordConfig) API_recordfile_modify added in v4.6.0

func (conf *RecordConfig) API_recordfile_modify(w http.ResponseWriter, r *http.Request)

func (*RecordConfig) API_start

func (conf *RecordConfig) API_start(w http.ResponseWriter, r *http.Request)

func (*RecordConfig) API_stop

func (conf *RecordConfig) API_stop(w http.ResponseWriter, r *http.Request)

func (*RecordConfig) OnEvent

func (conf *RecordConfig) OnEvent(event any)

func (*RecordConfig) ServeHTTP

func (conf *RecordConfig) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Recorder

type Recorder struct {
	Subscriber
	Storage  StorageConfig
	SkipTS   uint32
	Record   `json:"-" yaml:"-"`
	File     FileWr `json:"-" yaml:"-"`
	FileName string // 自定义文件名,分段录像无效
	// contains filtered or unexported fields
}

func (*Recorder) CreateFile

func (r *Recorder) CreateFile() (f FileWr, err error)

func (*Recorder) GetRecorder

func (r *Recorder) GetRecorder() *Recorder

func (*Recorder) OnEvent

func (r *Recorder) OnEvent(event any)

func (*Recorder) UploadFile added in v4.4.8

func (r *Recorder) UploadFile(filePath string, fileName string)

type StorageConfig added in v4.4.8

type StorageConfig struct {
	Endpoint  string
	AccessKey string
	SecretKey string
	Bucket    string
	UseSSL    bool
}

type VideoFileInfo

type VideoFileInfo struct {
	Path     string
	Size     int64
	Duration uint32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL