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

View File

@ -23,21 +23,6 @@ type InputItem struct {
ItemType string `json:"-"` 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 { type LogConfig struct {
PlayState bool `json:"play_state"` PlayState bool `json:"play_state"`
} }
@ -48,13 +33,13 @@ type ServerConfig struct {
} }
type Config struct { type Config struct {
Input []any `json:"input"` Input []any `json:"input"`
InputItems []InputItem `json:"-"` // contains video file or dir InputItems []InputItem `json:"-"` // contains video file or dir
VideoList []InputItem `json:"-"` // only contains video file VideoList []InputItem `json:"-"` // only contains video file
Play PlayConfig `json:"play"` Play map[string]any `json:"play"`
Output OutputConfig `json:"output"` Output OutputConfig `json:"output"`
Log LogConfig `json:"log"` Log LogConfig `json:"log"`
Server ServerConfig `json:"server"` Server ServerConfig `json:"server"`
} }
var GlobalConfig Config var GlobalConfig Config
@ -103,9 +88,6 @@ func validateConfig() error {
if err := validateOutputConfig(); err != nil { if err := validateOutputConfig(); err != nil {
return err return err
} }
if err := validatePlayConfig(); err != nil {
return err
}
if err := validateServerConfig(); err != nil { if err := validateServerConfig(); err != nil {
return err return err
} }
@ -195,43 +177,6 @@ func validateOutputConfig() error {
return nil 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 { func validateServerConfig() error {
if GlobalConfig.Server.Addr == "" { if GlobalConfig.Server.Addr == "" {
GlobalConfig.Server.Addr = ":8080" GlobalConfig.Server.Addr = ":8080"

View File

@ -20,21 +20,11 @@ func buildFFmpegArgs(videoItem config.InputItem) []string {
args = append(args, args = append(args,
"-i", videoPath, "-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 { for k, v := range config.GlobalConfig.Play {
args = append(args, config.GlobalConfig.Play.CustomArgs...) 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)) 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() { func (s *Streamer) actorLoop() {
for msg := range s.mailbox { for msg := range s.mailbox {
if msg.messageType() != CloseMessage.messageType(CloseMessage{}) { if msg.messageType() != CloseMessage.messageType(CloseMessage{}) {
log.Printf("handle %s start\n", msg.messageType())
s.wg.Add(1) s.wg.Add(1)
s.handleMessage(msg) s.handleMessage(msg)
s.wg.Done() s.wg.Done()
log.Printf("handle %s end\n", msg.messageType())
} else { } else {
s.handleMessage(msg) s.handleMessage(msg)
} }