m7s_plugin_record

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 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文件

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordExist = errors.New("recorder exist")
View Source
var RecordPluginConfig = &RecordConfig{
	DefaultYaml: defaultYaml,
	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:  ".",
	},
	Redis: nil,
}
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() error

func (*FLVRecorder) OnEvent

func (r *FLVRecorder) OnEvent(event any)

func (*FLVRecorder) Start

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

type FMP4Recorder

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

func NewFMP4Recorder

func NewFMP4Recorder() *FMP4Recorder

func (*FMP4Recorder) Close

func (r *FMP4Recorder) Close() error

func (*FMP4Recorder) OnEvent

func (r *FMP4Recorder) OnEvent(event any)

func (*FMP4Recorder) Start

func (r *FMP4Recorder) Start(streamPath string) (err 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

type IRecorder

type IRecorder interface {
	ISubscriber
	GetRecorder() *Recorder
	Start(streamPath 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)

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

type Record

type Record struct {
	Ext        string //文件扩展名
	Path       string //存储文件的目录
	AutoRecord bool
	Filter     string
	Fragment   time.Duration //分片大小,0表示不分片

	CreateFileFn  func(filename string, append bool) (FileWr, error) `json:"-" yaml:"-"`
	GetDurationFn func(file io.ReadSeeker) uint32                    `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

func (*Record) Init

func (r *Record) Init()

func (*Record) NeedRecord

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

func (*Record) ServeHTTP

func (r *Record) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Record) Tree

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

type RecordConfig

type RecordConfig struct {
	DefaultYaml
	config.Subscribe
	Flv      Record
	Mp4      Record
	Fmp4     Record
	Hls      Record
	Raw      Record
	RawAudio Record

	RedisConf RedisConfig
	Redis     *redis.Client `yaml:"-"`
	// contains filtered or unexported fields
}

func (*RecordConfig) API_list

func (conf *RecordConfig) API_list(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_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
	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)

type RedisConfig added in v1.0.7

type RedisConfig struct {
	Addr     string
	Password string
}

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