MCPcopy Create free account
hub / github.com/53AI/53AIHub / ResolveFFmpegToolchainPath

Function ResolveFFmpegToolchainPath

api/service/ffmpeg_toolchain.go:43–91  ·  view source on GitHub ↗

ResolveFFmpegToolchainPath 按项目优先级解析 ffmpeg 可执行文件路径。

()

Source from the content-addressed store, hash-verified

41
42// ResolveFFmpegToolchainPath 按项目优先级解析 ffmpeg 可执行文件路径。
43func ResolveFFmpegToolchainPath() (string, error) {
44 // 优先级1: 环境变量 FFMPEG_PATH
45 if path := strings.TrimSpace(os.Getenv("FFMPEG_PATH")); path != "" {
46 resolved, err := resolveFFmpegExecutableCandidate(path)
47 if err == nil && resolved != "" {
48 return resolved, nil
49 }
50 }
51
52 // 优先级2: 当前工作目录下的相对路径(适用于开发调试)
53 if wd, err := os.Getwd(); err == nil {
54 candidates := []string{
55 filepath.Join(wd, "bin", "ffmpeg", "ffmpeg"),
56 filepath.Join(wd, "bin", "ffmpeg"),
57 filepath.Join(wd, "ffmpeg", "ffmpeg"),
58 filepath.Join(wd, "ffmpeg"),
59 }
60 for _, candidate := range candidates {
61 if resolved, err := resolveFFmpegExecutableCandidate(candidate); err == nil {
62 return resolved, nil
63 }
64 }
65 }
66
67 // 优先级3: 基于可执行文件目录的相对路径(适用于部署环境)
68 if execPath, err := ffmpegToolchainExecutablePath(); err == nil {
69 appDir := filepath.Dir(execPath)
70 candidates := []string{
71 filepath.Join(appDir, "bin", "ffmpeg", "ffmpeg"),
72 filepath.Join(appDir, "bin", "ffmpeg"),
73 filepath.Join(appDir, "ffmpeg", "ffmpeg"),
74 filepath.Join(appDir, "ffmpeg"),
75 }
76 for _, candidate := range candidates {
77 if resolved, err := resolveFFmpegExecutableCandidate(candidate); err == nil {
78 return resolved, nil
79 }
80 }
81 }
82
83 // 优先级4: 系统 PATH
84 if path, err := ffmpegToolchainLookPath("ffmpeg"); err == nil {
85 if resolved, err := resolveFFmpegExecutableCandidate(path); err == nil {
86 return resolved, nil
87 }
88 }
89
90 return "", errors.New("未找到可用的 ffmpeg 可执行文件")
91}
92
93// CheckFFmpegToolchainCapabilitiesWithPath 使用指定路径探测 FFmpeg 能力。
94func CheckFFmpegToolchainCapabilitiesWithPath(ctx context.Context, path string, runner ffmpegToolchainCommandRunner) FFmpegToolchainResult {

Callers 4

TranscodeMethod · 0.85
TranscodeFromFileMethod · 0.85

Calls 2

NewMethod · 0.45

Tested by

no test coverage detected