Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions plugin/hls/pkg/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sync"
"time"

task "github.com/langhuihui/gotask"
"m7s.live/v5"
"m7s.live/v5/pkg/codec"
"m7s.live/v5/pkg/format"
Expand Down Expand Up @@ -63,6 +62,13 @@ func (w *HLSWriter) checkNoBodyRead() bool {
}

func (w *HLSWriter) Run() (err error) {
// 每次(重)启动时重置状态,避免 retry 后因残留 lastReadTime 立刻超时退出
w.lastReadTime = time.Time{}
w.hls_segment_count = 0
w.hls_playlist_count = 0
w.write_time = 0
w.memoryTs = sync.Map{}
w.M3u8.Reset()
if conf, ok := w.TransformJob.Config.Input.(string); ok {
ss := strings.Split(conf, "x")
if len(ss) != 2 {
Expand All @@ -88,10 +94,10 @@ func (w *HLSWriter) Run() (err error) {
}
MemoryTs.Store(w.TransformJob.StreamPath, w)
var audioCodec, videoCodec codec.FourCC
if subscriber.Publisher.HasAudioTrack() {
if subscriber.Publisher.HasAudioTrack() && subscriber.Publisher.AudioTrack.AVTrack != nil && subscriber.Publisher.AudioTrack.ICodecCtx != nil {
audioCodec = subscriber.Publisher.AudioTrack.FourCC()
}
if subscriber.Publisher.HasVideoTrack() {
if subscriber.Publisher.HasVideoTrack() && subscriber.Publisher.VideoTrack.AVTrack != nil && subscriber.Publisher.VideoTrack.ICodecCtx != nil {
videoCodec = subscriber.Publisher.VideoTrack.FourCC()
}
w.ts = &TsInMemory{}
Expand All @@ -100,12 +106,12 @@ func (w *HLSWriter) Run() (err error) {
return m7s.PlayBlock(subscriber, func(audio *format.Mpeg2Audio) error {
pesAudio.Pts = uint64(subscriber.AudioReader.AbsTime) * 90
if w.checkNoBodyRead() {
return errors.Join(ErrNoBodyRead, task.ErrStopByUser)
return ErrNoBodyRead
}
return pesAudio.WritePESPacket(audio.Memory, &w.ts.RecyclableMemory)
}, func(video *mpegts.VideoFrame) (err error) {
if w.checkNoBodyRead() {
return errors.Join(ErrNoBodyRead, task.ErrStopByUser)
return ErrNoBodyRead
}
vr := w.TransformJob.Subscriber.VideoReader
if vr.Value.IDR {
Expand Down
16 changes: 14 additions & 2 deletions plugin/rtsp/pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ func (c *Client) Run() (err error) {
return
}
default:
c.Warn("media kind not support", "kind", media.Kind)
codecNames := make([]string, len(media.Codecs))
for i, codec := range media.Codecs {
if codec != nil {
codecNames[i] = codec.Name
}
}
c.Warn("media kind not supported, will be skipped", "kind", media.Kind, "direction", media.Direction, "id", media.ID, "codecs", codecNames)
}
}

Expand Down Expand Up @@ -139,7 +145,13 @@ func (c *Client) Run() (err error) {
return
}
default:
c.Warn("media kind not support", "kind", media.Kind)
codecNames := make([]string, len(media.Codecs))
for i, codec := range media.Codecs {
if codec != nil {
codecNames[i] = codec.Name
}
}
c.Warn("media kind not supported, will be skipped", "kind", media.Kind, "direction", media.Direction, "id", media.ID, "codecs", codecNames)
}
}
if err = c.Record(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plugin/rtsp/pkg/transceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func (r *Receiver) SetMedia(medias []*Media) (err error) {
}
hasVideo = true // 标记找到视频
} else {
r.Stream.Warn("media kind not support", "kind", codec.Kind())
r.Stream.Warn("media codec not supported, will be skipped", "kind", codec.Kind(), "codecName", codec.Name, "payloadType", codec.PayloadType, "clockRate", codec.ClockRate)
}
}

Expand Down
16 changes: 14 additions & 2 deletions plugin/snap/pkg/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type SnapTask struct {
config SnapConfig
job *m7s.TransformJob
watermarkConfig *WatermarkConfig
ffmpegPath string
}

// saveSnap 保存截图
Expand All @@ -134,7 +135,11 @@ func (t *SnapTask) saveSnap(annexb []*format.AnnexB, snapMode int) error {

// 处理视频帧
var buf bytes.Buffer
if err := ProcessWithFFmpeg(annexb, &buf, ""); err != nil {
ffmpegPath := t.ffmpegPath
if ffmpegPath == "" {
ffmpegPath = "ffmpeg"
}
if err := ProcessWithFFmpeg(annexb, &buf, ffmpegPath); err != nil {
return fmt.Errorf("process with ffmpeg error: %w", err)
}

Expand Down Expand Up @@ -242,16 +247,23 @@ func NewTransform() m7s.ITransformer {

func (t *Transformer) Start() (err error) {
// 为每个输出配置创建一个截图任务
for _, output := range t.TransformJob.Config.Output {
t.Info("snap transform starting", "output_count", len(t.TransformJob.Config.Output))
for i, output := range t.TransformJob.Config.Output {
var task task.ITask
var snapConfig SnapConfig
if output.Conf != nil {
t.Info("output conf found", "index", i, "type", fmt.Sprintf("%T", output.Conf))
switch v := output.Conf.(type) {
case SnapConfig:
snapConfig = v
t.Info("parsed as SnapConfig", "timeinterval", snapConfig.TimeInterval, "iframeinterval", snapConfig.IFrameInterval, "savepath", snapConfig.SavePath)
case map[string]any:
t.Info("parsing as map[string]any", "content", v)
config.Parse(&snapConfig, v)
t.Info("parsed from map", "timeinterval", snapConfig.TimeInterval, "iframeinterval", snapConfig.IFrameInterval, "savepath", snapConfig.SavePath)
}
} else {
t.Warn("output.Conf is nil", "index", i)
}

// 初始化水印配置
Expand Down
4 changes: 4 additions & 0 deletions plugin/snap/pkg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func GetVideoFrame(publisher *m7s.Publisher, server *m7s.Server) ([]*format.Anne

// ProcessWithFFmpeg 使用 FFmpeg 处理视频帧并生成截图
func ProcessWithFFmpeg(annexb []*format.AnnexB, output io.Writer, FFMPEGPath string) error {
// 如果 FFMPEGPath 为空,使用默认值
if FFMPEGPath == "" {
FFMPEGPath = "ffmpeg"
}
// 创建ffmpeg命令,使用select过滤器选择最后一帧
cmd := exec.Command(FFMPEGPath, "-hide_banner", "-i", "pipe:0", "-vf", fmt.Sprintf("select='eq(n,%d)'", len(annexb)-1), "-vframes", "1", "-f", "mjpeg", "pipe:1")

Expand Down
3 changes: 0 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ func (l errLogger) Println(v ...interface{}) {
}

func (s *Server) Start() (err error) {
if err = util.CreateShutdownScript(); err != nil {
s.Error("create shutdown script error:", err)
}
s.Server = s
s.handler = s
httpConf, tcpConf := &s.config.HTTP, &s.config.TCP
Expand Down