You've already forked VptPassiveAdapter
tracer层级问题
This commit is contained in:
@ -21,15 +21,15 @@ import (
|
||||
const FfmpegExec = "ffmpeg"
|
||||
|
||||
func RunFfmpegTask(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
_, span := tracer.Start(ctx, "RunFfmpegTask")
|
||||
subCtx, span := tracer.Start(ctx, "RunFfmpegTask")
|
||||
defer span.End()
|
||||
var result bool
|
||||
if len(task.Files) == 1 {
|
||||
// 单个文件切割,用简单方法
|
||||
result = runFfmpegForSingleFile(ctx, task)
|
||||
result = runFfmpegForSingleFile(subCtx, task)
|
||||
} else {
|
||||
// 多个文件切割,用速度快的
|
||||
result = runFfmpegForMultipleFile1(ctx, task)
|
||||
result = runFfmpegForMultipleFile1(subCtx, task)
|
||||
}
|
||||
// 先尝试方法1
|
||||
if result {
|
||||
@ -38,7 +38,7 @@ func RunFfmpegTask(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
}
|
||||
log.Printf("FFMPEG简易方法失败,尝试复杂方法转码")
|
||||
// 不行再尝试方法二
|
||||
result = runFfmpegForMultipleFile2(ctx, task)
|
||||
result = runFfmpegForMultipleFile2(subCtx, task)
|
||||
if result {
|
||||
span.SetStatus(codes.Ok, "FFMPEG复杂方法成功")
|
||||
return true
|
||||
@ -48,7 +48,7 @@ func RunFfmpegTask(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
}
|
||||
|
||||
func runFfmpegForMultipleFile1(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
_, span := tracer.Start(ctx, "runFfmpegForMultipleFile1")
|
||||
subCtx, span := tracer.Start(ctx, "runFfmpegForMultipleFile1")
|
||||
defer span.End()
|
||||
// 多文件,方法一:先转换成ts,然后合并切割
|
||||
// 步骤一:先转换成ts,并行转换
|
||||
@ -61,7 +61,7 @@ func runFfmpegForMultipleFile1(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
go func(file *dto.File) {
|
||||
defer wg.Done()
|
||||
tmpFile := path.Join(os.TempDir(), file.Name+".ts")
|
||||
result, err := convertMp4ToTs(ctx, *file, tmpFile)
|
||||
result, err := convertMp4ToTs(subCtx, *file, tmpFile)
|
||||
if err != nil {
|
||||
log.Printf("转码出错: %v", err)
|
||||
mu.Lock()
|
||||
@ -88,7 +88,7 @@ func runFfmpegForMultipleFile1(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
}
|
||||
|
||||
// 步骤二:使用concat协议拼接裁切
|
||||
result, err := QuickConcatVideoCut(ctx, task.Files, int64(task.Offset), int64(task.Length), task.OutputFile)
|
||||
result, err := QuickConcatVideoCut(subCtx, task.Files, int64(task.Offset), int64(task.Length), task.OutputFile)
|
||||
if err != nil {
|
||||
span.SetAttributes(attribute.String("error", err.Error()))
|
||||
span.SetStatus(codes.Error, "FFMPEG多文件concat协议转码失败")
|
||||
@ -110,10 +110,10 @@ func runFfmpegForMultipleFile1(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
}
|
||||
|
||||
func runFfmpegForMultipleFile2(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
_, span := tracer.Start(ctx, "runFfmpegForMultipleFile2")
|
||||
subCtx, span := tracer.Start(ctx, "runFfmpegForMultipleFile2")
|
||||
defer span.End()
|
||||
// 多文件,方法二:使用计算资源编码
|
||||
result, err := SlowVideoCut(ctx, task.Files, int64(task.Offset), int64(task.Length), task.OutputFile)
|
||||
result, err := SlowVideoCut(subCtx, task.Files, int64(task.Offset), int64(task.Length), task.OutputFile)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@ -121,9 +121,9 @@ func runFfmpegForMultipleFile2(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
}
|
||||
|
||||
func runFfmpegForSingleFile(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
_, span := tracer.Start(ctx, "runFfmpegForSingleFile")
|
||||
subCtx, span := tracer.Start(ctx, "runFfmpegForSingleFile")
|
||||
defer span.End()
|
||||
result, err := QuickVideoCut(ctx, task.Files[0].Url, int64(task.Offset), int64(task.Length), task.OutputFile)
|
||||
result, err := QuickVideoCut(subCtx, task.Files[0].Url, int64(task.Offset), int64(task.Length), task.OutputFile)
|
||||
if err != nil {
|
||||
span.SetStatus(codes.Error, "FFMPEG单个文件裁切失败")
|
||||
return false
|
||||
@ -188,7 +188,7 @@ func CheckFileCoverageAndConstructTask(ctx context.Context, fileList []dto.File,
|
||||
}
|
||||
|
||||
func convertMp4ToTs(ctx context.Context, file dto.File, outFileName string) (bool, error) {
|
||||
_, span := tracer.Start(ctx, "convertMp4ToTs")
|
||||
subCtx, span := tracer.Start(ctx, "convertMp4ToTs")
|
||||
defer span.End()
|
||||
ffmpegCmd := []string{
|
||||
FfmpegExec,
|
||||
@ -200,11 +200,11 @@ func convertMp4ToTs(ctx context.Context, file dto.File, outFileName string) (boo
|
||||
"-f", "mpegts",
|
||||
outFileName,
|
||||
}
|
||||
return handleFfmpegProcess(ctx, ffmpegCmd)
|
||||
return handleFfmpegProcess(subCtx, ffmpegCmd)
|
||||
}
|
||||
|
||||
func convertHevcToTs(ctx context.Context, file dto.File, outFileName string) (bool, error) {
|
||||
_, span := tracer.Start(ctx, "convertHevcToTs")
|
||||
subCtx, span := tracer.Start(ctx, "convertHevcToTs")
|
||||
defer span.End()
|
||||
ffmpegCmd := []string{
|
||||
FfmpegExec,
|
||||
@ -216,11 +216,11 @@ func convertHevcToTs(ctx context.Context, file dto.File, outFileName string) (bo
|
||||
"-f", "mpegts",
|
||||
outFileName,
|
||||
}
|
||||
return handleFfmpegProcess(ctx, ffmpegCmd)
|
||||
return handleFfmpegProcess(subCtx, ffmpegCmd)
|
||||
}
|
||||
|
||||
func QuickVideoCut(ctx context.Context, inputFile string, offset, length int64, outputFile string) (bool, error) {
|
||||
_, span := tracer.Start(ctx, "QuickVideoCut")
|
||||
subCtx, span := tracer.Start(ctx, "QuickVideoCut")
|
||||
defer span.End()
|
||||
ffmpegCmd := []string{
|
||||
FfmpegExec,
|
||||
@ -236,11 +236,11 @@ func QuickVideoCut(ctx context.Context, inputFile string, offset, length int64,
|
||||
"-f", "mp4",
|
||||
outputFile,
|
||||
}
|
||||
return handleFfmpegProcess(ctx, ffmpegCmd)
|
||||
return handleFfmpegProcess(subCtx, ffmpegCmd)
|
||||
}
|
||||
|
||||
func QuickConcatVideoCut(ctx context.Context, inputFiles []dto.File, offset, length int64, outputFile string) (bool, error) {
|
||||
_, span := tracer.Start(ctx, "QuickConcatVideoCut")
|
||||
subCtx, span := tracer.Start(ctx, "QuickConcatVideoCut")
|
||||
defer span.End()
|
||||
tmpFile := fmt.Sprintf("tmp%.10f.txt", rand.Float64())
|
||||
tmpFileObj, err := os.Create(tmpFile)
|
||||
@ -277,11 +277,11 @@ func QuickConcatVideoCut(ctx context.Context, inputFiles []dto.File, offset, len
|
||||
"-f", "mp4",
|
||||
outputFile,
|
||||
}
|
||||
return handleFfmpegProcess(ctx, ffmpegCmd)
|
||||
return handleFfmpegProcess(subCtx, ffmpegCmd)
|
||||
}
|
||||
|
||||
func SlowVideoCut(ctx context.Context, inputFiles []dto.File, offset, length int64, outputFile string) (bool, error) {
|
||||
_, span := tracer.Start(ctx, "SlowVideoCut")
|
||||
subCtx, span := tracer.Start(ctx, "SlowVideoCut")
|
||||
defer span.End()
|
||||
ffmpegCmd := []string{
|
||||
FfmpegExec,
|
||||
@ -311,7 +311,7 @@ func SlowVideoCut(ctx context.Context, inputFiles []dto.File, offset, length int
|
||||
outputFile,
|
||||
)
|
||||
|
||||
return handleFfmpegProcess(ctx, ffmpegCmd)
|
||||
return handleFfmpegProcess(subCtx, ffmpegCmd)
|
||||
}
|
||||
|
||||
func handleFfmpegProcess(ctx context.Context, ffmpegCmd []string) (bool, error) {
|
||||
|
Reference in New Issue
Block a user