You've already forked VptPassiveAdapter
fix(video): 修复视频剪辑功能中的参数错误和音频处理问题
- 修正 SlowVideoCut 函数中传入的参数,将第二个 task.Offset 替换为 task.Length - 添加静音音频源输入以解决无音频轨道的视频处理问题 - 配置音频编解码器为 aac 格式并启用最短时长截取 - 在多个视频处理函数中统一音频处理逻辑 - 修复 concat 方式视频剪辑的音频映射问题 - 确保视频剪辑操作保留正确的音频流处理
This commit is contained in:
@@ -147,7 +147,7 @@ func runFfmpegForMultipleFile2(ctx context.Context, task *dto.FfmpegTask) bool {
|
|||||||
subCtx, span := tracer.Start(ctx, "runFfmpegForMultipleFile2")
|
subCtx, span := tracer.Start(ctx, "runFfmpegForMultipleFile2")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
// 多文件,方法二:使用计算资源编码
|
// 多文件,方法二:使用计算资源编码
|
||||||
result, err := SlowVideoCut(subCtx, task.Files, task.Offset, task.Offset, task.OutputFile)
|
result, err := SlowVideoCut(subCtx, task.Files, task.Offset, task.Length, task.OutputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -317,8 +317,10 @@ func QuickVideoCut(ctx context.Context, inputFile string, offset, length float64
|
|||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-y",
|
"-y",
|
||||||
"-i", inputFile,
|
"-i", inputFile,
|
||||||
|
"-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100",
|
||||||
"-c:v", "copy",
|
"-c:v", "copy",
|
||||||
"-an",
|
"-c:a", "aac",
|
||||||
|
"-shortest",
|
||||||
"-reset_timestamps", "1",
|
"-reset_timestamps", "1",
|
||||||
"-ss", strconv.FormatFloat(offset, 'f', 2, 64),
|
"-ss", strconv.FormatFloat(offset, 'f', 2, 64),
|
||||||
"-t", strconv.FormatFloat(length, 'f', 2, 64),
|
"-t", strconv.FormatFloat(length, 'f', 2, 64),
|
||||||
@@ -360,8 +362,10 @@ func QuickConcatVideoCut(ctx context.Context, inputFiles []dto.File, offset, len
|
|||||||
"-f", "concat",
|
"-f", "concat",
|
||||||
"-safe", "0",
|
"-safe", "0",
|
||||||
"-i", tmpFile,
|
"-i", tmpFile,
|
||||||
|
"-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100",
|
||||||
"-c:v", "copy",
|
"-c:v", "copy",
|
||||||
"-an",
|
"-c:a", "aac",
|
||||||
|
"-shortest",
|
||||||
"-ss", strconv.FormatFloat(offset, 'f', 2, 64),
|
"-ss", strconv.FormatFloat(offset, 'f', 2, 64),
|
||||||
"-t", strconv.FormatFloat(length, 'f', 2, 64),
|
"-t", strconv.FormatFloat(length, 'f', 2, 64),
|
||||||
"-f", "mp4",
|
"-f", "mp4",
|
||||||
@@ -383,6 +387,9 @@ func SlowVideoCut(ctx context.Context, inputFiles []dto.File, offset, length flo
|
|||||||
ffmpegCmd = append(ffmpegCmd, "-i", file.Url)
|
ffmpegCmd = append(ffmpegCmd, "-i", file.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加静音音频源作为额外输入
|
||||||
|
ffmpegCmd = append(ffmpegCmd, "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=44100")
|
||||||
|
|
||||||
inputCount := len(inputFiles)
|
inputCount := len(inputFiles)
|
||||||
filterComplex := strings.Builder{}
|
filterComplex := strings.Builder{}
|
||||||
for i := 0; i < inputCount; i++ {
|
for i := 0; i < inputCount; i++ {
|
||||||
@@ -393,8 +400,10 @@ func SlowVideoCut(ctx context.Context, inputFiles []dto.File, offset, length flo
|
|||||||
ffmpegCmd = append(ffmpegCmd,
|
ffmpegCmd = append(ffmpegCmd,
|
||||||
"-filter_complex", filterComplex.String(),
|
"-filter_complex", filterComplex.String(),
|
||||||
"-map", "[v]",
|
"-map", "[v]",
|
||||||
|
"-map", fmt.Sprintf("%d:a", inputCount),
|
||||||
|
"-c:a", "aac",
|
||||||
|
"-shortest",
|
||||||
"-preset:v", "fast",
|
"-preset:v", "fast",
|
||||||
"-an",
|
|
||||||
"-ss", strconv.FormatFloat(offset, 'f', 2, 64),
|
"-ss", strconv.FormatFloat(offset, 'f', 2, 64),
|
||||||
"-t", strconv.FormatFloat(length, 'f', 2, 64),
|
"-t", strconv.FormatFloat(length, 'f', 2, 64),
|
||||||
"-f", "mp4",
|
"-f", "mp4",
|
||||||
|
|||||||
Reference in New Issue
Block a user