diff --git a/config.yaml b/config.yaml index 76ea750..fe2da71 100644 --- a/config.yaml +++ b/config.yaml @@ -32,6 +32,7 @@ disconnectAction: enabled: false thresholdMinutes: 5 command: "" +addSilentAudio: true preview: enabled: true hwaccel: "" diff --git a/config/dto.go b/config/dto.go index 88f8759..7942e1b 100644 --- a/config/dto.go +++ b/config/dto.go @@ -78,4 +78,5 @@ type MainConfig struct { Viid ViidConfig `mapstructure:"viid"` DisconnectAction DisconnectActionConfig `mapstructure:"disconnectAction"` Preview PreviewConfig `mapstructure:"preview"` + AddSilentAudio bool `mapstructure:"addSilentAudio"` } diff --git a/util/ffmpeg.go b/util/ffmpeg.go index fefe3ae..0dbd33b 100644 --- a/util/ffmpeg.go +++ b/util/ffmpeg.go @@ -334,15 +334,26 @@ func QuickVideoCut(ctx context.Context, inputFile string, offset, length float64 "-y", "-ss", strconv.FormatFloat(offset, 'f', 2, 64), "-i", inputFile, - "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100", - "-c:v", "copy", - "-c:a", "aac", - "-shortest", + } + if config.Config.AddSilentAudio { + ffmpegCmd = append(ffmpegCmd, + "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100", + "-c:v", "copy", + "-c:a", "aac", + "-shortest", + ) + } else { + ffmpegCmd = append(ffmpegCmd, + "-c:v", "copy", + "-an", + ) + } + ffmpegCmd = append(ffmpegCmd, "-t", strconv.FormatFloat(length, 'f', 2, 64), "-fflags", "+genpts", "-f", "mp4", outputFile, - } + ) return handleFfmpegProcess(subCtx, ffmpegCmd) } @@ -378,15 +389,26 @@ func QuickConcatVideoCut(ctx context.Context, inputFiles []dto.File, offset, len "-safe", "0", "-ss", strconv.FormatFloat(offset, 'f', 2, 64), "-i", tmpFile, - "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100", - "-c:v", "copy", - "-c:a", "aac", - "-shortest", + } + if config.Config.AddSilentAudio { + ffmpegCmd = append(ffmpegCmd, + "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100", + "-c:v", "copy", + "-c:a", "aac", + "-shortest", + ) + } else { + ffmpegCmd = append(ffmpegCmd, + "-c:v", "copy", + "-an", + ) + } + ffmpegCmd = append(ffmpegCmd, "-t", strconv.FormatFloat(length, 'f', 2, 64), "-fflags", "+genpts", "-f", "mp4", outputFile, - } + ) return handleFfmpegProcess(subCtx, ffmpegCmd) } @@ -403,10 +425,13 @@ func SlowVideoCut(ctx context.Context, inputFiles []dto.File, offset, length flo ffmpegCmd = append(ffmpegCmd, "-i", file.Url) } - // 添加静音音频源作为额外输入 - ffmpegCmd = append(ffmpegCmd, "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100") - inputCount := len(inputFiles) + + if config.Config.AddSilentAudio { + // 添加静音音频源作为额外输入 + ffmpegCmd = append(ffmpegCmd, "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100") + } + filterComplex := strings.Builder{} for i := 0; i < inputCount; i++ { filterComplex.WriteString(fmt.Sprintf("[%d:v]", i)) @@ -416,9 +441,19 @@ func SlowVideoCut(ctx context.Context, inputFiles []dto.File, offset, length flo ffmpegCmd = append(ffmpegCmd, "-filter_complex", filterComplex.String(), "-map", "[v]", - "-map", fmt.Sprintf("%d:a", inputCount), - "-c:a", "aac", - "-shortest", + ) + + if config.Config.AddSilentAudio { + ffmpegCmd = append(ffmpegCmd, + "-map", fmt.Sprintf("%d:a", inputCount), + "-c:a", "aac", + "-shortest", + ) + } else { + ffmpegCmd = append(ffmpegCmd, "-an") + } + + ffmpegCmd = append(ffmpegCmd, "-preset:v", "fast", "-ss", strconv.FormatFloat(offset, 'f', 2, 64), "-t", strconv.FormatFloat(length, 'f', 2, 64),