feat: 新增ffmpeg文件分片功能 (#545)

* feat: 新增ffmpeg文件分片功能

* 修改按文件尺寸分段参数的默认值等行为

---------

Co-authored-by: kira1928 <kira1928@gmail.com>
This commit is contained in:
nopastandkira1928 authored and GitHub committed 2023-09-18 23:22:30 +09:00
1 parent a6f1ac23ad
commit 08079176a8
3 files changed
+21 -4

No files matched your search

+5
View File
@@ -25,6 +25,11 @@ out_put_tmpl: ""
video_split_strategies:
on_room_name_changed: false
max_duration: 0s
# 仅在 use_native_flv_parser=false 时生效
# 单位为字节 (byte)
# 有效值为正数,默认值 0 为无效
# 负数为非法值,程序会输出 log 提醒,并无视所设定的数值
max_file_size: 0
cookies: {}
on_record_finished:
convert_to_mp4: false
+1
View File
@@ -46,6 +46,7 @@ type Feature struct {
type VideoSplitStrategies struct {
OnRoomNameChanged bool `yaml:"on_room_name_changed"`
MaxDuration time.Duration `yaml:"max_duration"`
MaxFileSize int `yaml:"max_file_size"`
}
// On record finished actions.
+15 -4
View File
@@ -8,9 +8,11 @@ import (
"net/url"
"os"
"os/exec"
"strconv"
"sync"
"time"
"github.com/hr3lxphr6j/bililive-go/src/instance"
"github.com/hr3lxphr6j/bililive-go/src/live"
"github.com/hr3lxphr6j/bililive-go/src/pkg/parser"
"github.com/hr3lxphr6j/bililive-go/src/pkg/utils"
@@ -127,8 +129,7 @@ func (p *Parser) ParseLiveStream(ctx context.Context, url *url.URL, live live.Li
if err != nil {
return err
}
p.cmd = exec.Command(
ffmpegPath,
args := []string{
"-nostats",
"-progress", "-",
"-y", "-re",
@@ -138,8 +139,18 @@ func (p *Parser) ParseLiveStream(ctx context.Context, url *url.URL, live live.Li
"-i", url.String(),
"-c", "copy",
"-bsf:a", "aac_adtstoasc",
file,
)
}
inst := instance.GetInstance(ctx)
MaxFileSize := inst.Config.VideoSplitStrategies.MaxFileSize
if MaxFileSize < 0 {
inst.Logger.Infof("Invalid MaxFileSize: %d", MaxFileSize)
} else if MaxFileSize > 0 {
args = append(args, "-fs", strconv.Itoa(MaxFileSize))
}
args = append(args, file)
p.cmd = exec.Command(ffmpegPath, args...)
if p.cmdStdIn, err = p.cmd.StdinPipe(); err != nil {
return err
}