breaking change: remove default ffmpeg args

This commit is contained in:
Nite07 2024-10-27 22:53:25 +08:00
parent 048dfecbae
commit dcdbf84c8c
4 changed files with 21 additions and 89 deletions

View File

@ -30,18 +30,17 @@
}
],
"play": {
"video_codec": "libx264",
"preset": "medium",
"crf": 23,
"max_rate": "1000k",
"buf_size": "2000k",
"scale": "1920:1080",
"frame_rate": 30,
"audio_codec": "aac",
"audio_bitrate": "128k",
"audio_sample_rate": 44100,
"output_format": "flv",
"custom_args": []
"-c:v": "libx264",
"-preset": "medium",
"-crf": 23,
"-maxrate": "1000k",
"-bufsize": "2000k",
"-vf": "1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2",
"-r": 30,
"-c:a": "aac",
"-b:a": "128k",
"-ar": 44100,
"-f": "flv"
},
"output": {
"rtmp_server": "rtmp://live-push.example.com/live",

View File

@ -23,21 +23,6 @@ type InputItem struct {
ItemType string `json:"-"`
}
type PlayConfig struct {
VideoCodec string `json:"video_codec"`
Preset string `json:"preset"`
CRF int `json:"crf"`
MaxRate string `json:"max_rate"`
BufSize string `json:"buf_size"`
Scale string `json:"scale"`
FrameRate int `json:"frame_rate"`
AudioCodec string `json:"audio_codec"`
AudioBitrate string `json:"audio_bitrate"`
AudioSampleRate int `json:"audio_sample_rate"`
OutputFormat string `json:"output_format"`
CustomArgs []string `json:"custom_args"`
}
type LogConfig struct {
PlayState bool `json:"play_state"`
}
@ -51,7 +36,7 @@ type Config struct {
Input []any `json:"input"`
InputItems []InputItem `json:"-"` // contains video file or dir
VideoList []InputItem `json:"-"` // only contains video file
Play PlayConfig `json:"play"`
Play map[string]any `json:"play"`
Output OutputConfig `json:"output"`
Log LogConfig `json:"log"`
Server ServerConfig `json:"server"`
@ -103,9 +88,6 @@ func validateConfig() error {
if err := validateOutputConfig(); err != nil {
return err
}
if err := validatePlayConfig(); err != nil {
return err
}
if err := validateServerConfig(); err != nil {
return err
}
@ -195,43 +177,6 @@ func validateOutputConfig() error {
return nil
}
func validatePlayConfig() error {
if GlobalConfig.Play.VideoCodec == "" {
GlobalConfig.Play.VideoCodec = "libx264"
}
if GlobalConfig.Play.Preset == "" {
GlobalConfig.Play.Preset = "fast"
}
if GlobalConfig.Play.CRF == 0 {
GlobalConfig.Play.CRF = 23
}
if GlobalConfig.Play.MaxRate == "" {
GlobalConfig.Play.MaxRate = "8000k"
}
if GlobalConfig.Play.BufSize == "" {
GlobalConfig.Play.BufSize = "12000k"
}
if GlobalConfig.Play.Scale == "" {
GlobalConfig.Play.Scale = "1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2"
}
if GlobalConfig.Play.FrameRate == 0 {
GlobalConfig.Play.FrameRate = 30
}
if GlobalConfig.Play.AudioCodec == "" {
GlobalConfig.Play.AudioCodec = "aac"
}
if GlobalConfig.Play.AudioBitrate == "" {
GlobalConfig.Play.AudioBitrate = "192k"
}
if GlobalConfig.Play.AudioSampleRate == 0 {
GlobalConfig.Play.AudioSampleRate = 48000
}
if GlobalConfig.Play.OutputFormat == "" {
GlobalConfig.Play.OutputFormat = "flv"
}
return nil
}
func validateServerConfig() error {
if GlobalConfig.Server.Addr == "" {
GlobalConfig.Server.Addr = ":8080"

View File

@ -20,21 +20,11 @@ func buildFFmpegArgs(videoItem config.InputItem) []string {
args = append(args,
"-i", videoPath,
"-c:v", config.GlobalConfig.Play.VideoCodec,
"-preset", config.GlobalConfig.Play.Preset,
"-crf", fmt.Sprintf("%d", config.GlobalConfig.Play.CRF),
"-maxrate", config.GlobalConfig.Play.MaxRate,
"-bufsize", config.GlobalConfig.Play.BufSize,
"-vf", fmt.Sprintf("scale=%s", config.GlobalConfig.Play.Scale),
"-r", fmt.Sprintf("%d", config.GlobalConfig.Play.FrameRate),
"-c:a", config.GlobalConfig.Play.AudioCodec,
"-b:a", config.GlobalConfig.Play.AudioBitrate,
"-ar", fmt.Sprintf("%d", config.GlobalConfig.Play.AudioSampleRate),
"-f", config.GlobalConfig.Play.OutputFormat,
)
if len(config.GlobalConfig.Play.CustomArgs) != 0 {
args = append(args, config.GlobalConfig.Play.CustomArgs...)
for k, v := range config.GlobalConfig.Play {
args = append(args, k)
args = append(args, fmt.Sprint(v))
}
args = append(args, fmt.Sprintf("%s/%s", config.GlobalConfig.Output.RTMPServer, config.GlobalConfig.Output.StreamKey))

View File

@ -56,11 +56,9 @@ func NewStreamer(videoList []config.InputItem) *Streamer {
func (s *Streamer) actorLoop() {
for msg := range s.mailbox {
if msg.messageType() != CloseMessage.messageType(CloseMessage{}) {
log.Printf("handle %s start\n", msg.messageType())
s.wg.Add(1)
s.handleMessage(msg)
s.wg.Done()
log.Printf("handle %s end\n", msg.messageType())
} else {
s.handleMessage(msg)
}