You've already forked VptPassiveAdapter
feat(video): 支持HEVC编码视频转换为TS格式
- 添加GetVideoCodec函数用于检测视频编码格式 - 实现HEVC编码视频的特殊转换逻辑 - 引入convertHevcToTs函数处理HEVC编码视频 - 保持原有MP4格式转换功能的兼容性 - 添加错误处理和日志记录机制 - 集成链路追踪支持视频编解码操作监控
This commit is contained in:
@@ -79,7 +79,20 @@ func runFfmpegForMultipleFile1(ctx context.Context, task *dto.FfmpegTask) bool {
|
||||
go func(file *dto.File) {
|
||||
defer wg.Done()
|
||||
tmpFile := path.Join(os.TempDir(), file.Name+strconv.Itoa(rand.Int())+".ts")
|
||||
result, err := convertMp4ToTs(subCtx, *file, tmpFile)
|
||||
codec, err := GetVideoCodec(subCtx, file.Url)
|
||||
if err != nil {
|
||||
logger.Error("获取视频编码失败", zap.Error(err))
|
||||
mu.Lock()
|
||||
notOk = true
|
||||
mu.Unlock()
|
||||
return
|
||||
}
|
||||
var result bool
|
||||
if codec == "hevc" {
|
||||
result, err = convertHevcToTs(subCtx, *file, tmpFile)
|
||||
} else {
|
||||
result, err = convertMp4ToTs(subCtx, *file, tmpFile)
|
||||
}
|
||||
if err != nil {
|
||||
logger.Error("转码出错", zap.Error(err))
|
||||
mu.Lock()
|
||||
@@ -466,6 +479,33 @@ func handleFfmpegProcess(ctx context.Context, ffmpegCmd []string) (bool, error)
|
||||
}
|
||||
}
|
||||
|
||||
func GetVideoCodec(ctx context.Context, filePath string) (string, error) {
|
||||
_, span := tracer.Start(ctx, "GetVideoCodec")
|
||||
defer span.End()
|
||||
ffprobeCmd := []string{
|
||||
"ffprobe",
|
||||
"-v", "error",
|
||||
"-select_streams", "v:0",
|
||||
"-show_entries", "stream=codec_name",
|
||||
"-of", "default=noprint_wrappers=1:nokey=1",
|
||||
filePath,
|
||||
}
|
||||
span.SetAttributes(attribute.String("ffprobe.cmd", ToJson(ffprobeCmd)))
|
||||
cmd := exec.Command(ffprobeCmd[0], ffprobeCmd[1:]...)
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
span.SetAttributes(attribute.String("error", err.Error()))
|
||||
span.SetStatus(codes.Error, "获取视频编码失败")
|
||||
return "", fmt.Errorf("failed to get video codec: %w", err)
|
||||
}
|
||||
codec := strings.TrimSpace(out.String())
|
||||
span.SetAttributes(attribute.String("video.codec", codec))
|
||||
return codec, nil
|
||||
}
|
||||
|
||||
func GetVideoDuration(ctx context.Context, filePath string) (float64, error) {
|
||||
_, span := tracer.Start(ctx, "GetVideoDuration")
|
||||
defer span.End()
|
||||
|
||||
Reference in New Issue
Block a user