You've already forked VptPassiveAdapter
静音音频流
This commit is contained in:
@@ -32,6 +32,7 @@ disconnectAction:
|
||||
enabled: false
|
||||
thresholdMinutes: 5
|
||||
command: ""
|
||||
addSilentAudio: true
|
||||
preview:
|
||||
enabled: true
|
||||
hwaccel: ""
|
||||
|
||||
@@ -78,4 +78,5 @@ type MainConfig struct {
|
||||
Viid ViidConfig `mapstructure:"viid"`
|
||||
DisconnectAction DisconnectActionConfig `mapstructure:"disconnectAction"`
|
||||
Preview PreviewConfig `mapstructure:"preview"`
|
||||
AddSilentAudio bool `mapstructure:"addSilentAudio"`
|
||||
}
|
||||
|
||||
@@ -334,15 +334,26 @@ func QuickVideoCut(ctx context.Context, inputFile string, offset, length float64
|
||||
"-y",
|
||||
"-ss", strconv.FormatFloat(offset, 'f', 2, 64),
|
||||
"-i", inputFile,
|
||||
}
|
||||
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,
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
inputCount := len(inputFiles)
|
||||
|
||||
if config.Config.AddSilentAudio {
|
||||
// 添加静音音频源作为额外输入
|
||||
ffmpegCmd = append(ffmpegCmd, "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100")
|
||||
}
|
||||
|
||||
inputCount := len(inputFiles)
|
||||
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]",
|
||||
)
|
||||
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user