From: qydysky Date: Sun, 9 Apr 2023 04:06:24 +0000 (+0800) Subject: Fix 快速切片下的指定房间录制回调 X-Git-Tag: v0.8.0~2 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=67506cf3c09ec61591fc2be63caf977b39f68fa9;p=bili_danmu%2F.git Fix 快速切片下的指定房间录制回调 --- diff --git a/Reply/stream.go b/Reply/stream.go index 9bf3705..81f042a 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -57,7 +57,6 @@ type M4SStream struct { Callback_stopRec func(*M4SStream) //录制结束的回调 Callback_stop func(*M4SStream) //实例结束的回调 reqPool *pool.Buf[reqf.Req] //请求池 - duration time.Duration //录制时长 } type M4SStream_Config struct { @@ -608,7 +607,6 @@ func (t *M4SStream) saveStream() (e error) { } // 获取流 - startT := time.Now() switch t.stream_type { case `mp4`: e = t.saveStreamM4s() @@ -618,7 +616,6 @@ func (t *M4SStream) saveStream() (e error) { e = errors.New("undefind stream type") t.log.L(`E: `, e) } - t.duration = time.Since(startT) return } @@ -1130,6 +1127,7 @@ func (t *M4SStream) Start() bool { t.Stream_msg = msgq.NewType[[]byte]() // 设置事件 + // 当录制停止时,取消全部录制 mainContextC, mainCancle := context.WithCancel(context.Background()) if t.Callback_stopRec != nil { t.msg.Pull_tag_only("stopRec", func(ms *M4SStream) (disable bool) { @@ -1145,10 +1143,12 @@ func (t *M4SStream) Start() bool { t.msg.ClearAll() return true }) + if t.config.save_to_file { var fc funcCtrl.FlashFunc t.msg.Pull_tag_async(map[string]func(*M4SStream) (disable bool){ `cut`: func(ms *M4SStream) (disable bool) { + // 当cut时,取消上次录制 contextC, cancle := context.WithCancel(mainContextC) fc.FlashWithCallback(cancle) @@ -1162,55 +1162,59 @@ func (t *M4SStream) Start() bool { return nil } ms.getSavepath() - go StartRecDanmu(contextC, ms.Current_save_path+"0.csv") //保存弹幕 - go Ass_f(contextC, ms.Current_save_path, ms.Current_save_path+"0", time.Now()) //开始ass - if e := ms.PusherToFile(contextC, ms.Current_save_path+`0.`+ms.stream_type, startf, stopf); e != nil { - l.L(`E: `, e) - } - return false - }, - }) - } - defer t.msg.Push_tag(`stop`, t) + var ( + cp = ms.Current_save_path + st = ms.stream_type + cr = ms.common.Roomid + ) - //指定房间录制回调 - if v, ok := t.common.K_v.LoadV("指定房间录制回调").([]any); ok && len(v) > 0 { - for i := 0; i < len(v); i++ { - if vm, ok := v[i].(map[string]any); ok { - if roomid, ok := vm["roomid"].(float64); ok && int(roomid) == t.common.Roomid { - var ( - durationS, _ = vm["durationS"].(float64) - after, _ = vm["after"].([]any) - ) - - if len(after) > 2 { - t.msg.Pull_tag_async_only("stopRec", func(ms *M4SStream) (disable bool) { - if durationS >= 0 && ms.duration.Seconds() > durationS { - var cmds []string - for i := 0; i < len(after); i++ { - if cmd, ok := after[i].(string); ok && cmd != "" { - cmds = append(cmds, strings.ReplaceAll(cmd, "{type}", ms.stream_type)) + go StartRecDanmu(contextC, cp+"0.csv") //保存弹幕 + go Ass_f(contextC, cp, cp+"0", time.Now()) //开始ass + startT := time.Now() + if e := ms.PusherToFile(contextC, cp+`0.`+st, startf, stopf); e != nil { + l.L(`E: `, e) + } + duration := time.Since(startT) + + //指定房间录制回调 + if v, ok := ms.common.K_v.LoadV("指定房间录制回调").([]any); ok && len(v) > 0 { + l := l.Base(`录制回调`) + for i := 0; i < len(v); i++ { + if vm, ok := v[i].(map[string]any); ok { + if roomid, ok := vm["roomid"].(float64); ok && int(roomid) == cr { + var ( + durationS, _ = vm["durationS"].(float64) + after, _ = vm["after"].([]any) + ) + if len(after) >= 2 && durationS >= 0 && duration.Seconds() > durationS { + var cmds []string + for i := 0; i < len(after); i++ { + if cmd, ok := after[i].(string); ok && cmd != "" { + cmds = append(cmds, strings.ReplaceAll(cmd, "{type}", st)) + } } - } - l := t.log.Base_add(`指定房间录制回调`) - cmd := exec.Command(cmds[0], cmds[1:]...) - cmd.Dir = ms.Current_save_path - l.L(`I: `, "启动", cmd.Args) - if e := cmd.Run(); e != nil { - l.L(`E: `, e) + cmd := exec.Command(cmds[0], cmds[1:]...) + cmd.Dir = cp + l.L(`I: `, "启动", cmd.Args) + if e := cmd.Run(); e != nil { + l.L(`E: `, e) + } + l.L(`I: `, "结束") } - l.L(`I: `, "结束") } - return false - }) + } } } - } - } + + return false + }, + }) } + defer t.msg.Push_tag(`stop`, t) + // 主循环 for t.Status.Islive() { // 是否在直播 @@ -1233,7 +1237,7 @@ func (t *M4SStream) Start() bool { } } - t.log.L(`I: `, `结束录制(`+strconv.Itoa(t.common.Roomid)+`) 时长(`+t.duration.String()+`)`) + t.log.L(`I: `, `结束录制(`+strconv.Itoa(t.common.Roomid)+`)`) t.exitSign.Done() }() return true diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index 8800883..b4d3308 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -71,7 +71,7 @@ "danmu":"" } ], - "指定房间录制回调-help":"当指定roomid的房间结束录制后触发对应的命令,命令执行目录为录播目录,占位符({type}:视频类型),durationS:录制时长超过指定秒数才触发", + "指定房间录制回调-help":"当指定roomid的房间结束录制后(包含切片)触发对应的命令,命令执行目录为录播目录,占位符({type}:视频类型),durationS:录制时长超过指定秒数才触发", "指定房间录制回调":[ { "roomid":0,