创建时间: 2025-02-03
错误: 'ffmpeg.exe' 不是内部或外部命令
文件: apps/desktop/src/main/pipeline-realtime-v2.cjs
行号: 375
错误代码:
const process = spawn('ffmpeg', args);-
直接使用 'ffmpeg'
- 代码直接使用
spawn('ffmpeg', ...) - 依赖系统 PATH 环境变量
- Windows 下可能找不到 ffmpeg.exe
- 代码直接使用
-
其他地方正确使用
generator.cjs中的runFFmpeg函数正确使用了完整路径- 其他模块都使用
ffmpeg-static提供的完整路径
-
不一致导致错误
- 流水线模块使用相对路径
- 系统找不到 FFmpeg 可执行文件
文件: apps/desktop/src/main/pipeline-realtime-v2.cjs
位置: 行 1-15
添加:
const { spawn } = require('child_process');
// FFmpeg 路径
const ffmpegStatic = require('ffmpeg-static');
const { getBinaryPath } = require('../utils/binaryPath');
const ffmpegPath = getBinaryPath(ffmpegStatic);文件: apps/desktop/src/main/pipeline-realtime-v2.cjs
位置: 行 378-384
修改前:
logFn('info', `🔗 拼接 ${blockFiles.length} 个块...`);
await new Promise((resolve, reject) => {
const process = spawn('ffmpeg', args);修改后:
logFn('info', `🔗 拼接 ${blockFiles.length} 个块...`);
// 获取 FFmpeg 可执行文件路径
const ffmpegExecutable = typeof ffmpegPath === 'string' ? ffmpegPath : ffmpegPath.path;
await new Promise((resolve, reject) => {
const process = spawn(ffmpegExecutable, args, { windowsHide: true });项目使用 ffmpeg-static 包来管理 FFmpeg:
const ffmpegStatic = require('ffmpeg-static');
// 返回: "F:\\...\\node_modules\\ffmpeg-static\\bin\\win32\\x64\\ffmpeg.exe"// apps/desktop/src/main/utils/binaryPath.js
function getBinaryPath(binary) {
// 处理不同格式的 binary 对象
if (typeof binary === 'string') {
return binary;
}
if (binary && binary.path) {
return binary.path;
}
throw new Error('Invalid binary');
}-
Windows 系统限制
- FFmpeg 不在系统 PATH 中
- 需要完整路径才能执行
-
依赖管理
- 项目通过 npm 管理依赖
- FFmpeg 在
node_modules中 - 必须使用完整路径
-
跨平台兼容性
- 不同操作系统路径不同
ffmpeg-static自动处理平台差异
-
✅ 导入正确
const ffmpegStatic = require('ffmpeg-static'); const { getBinaryPath } = require('../utils/binaryPath'); const ffmpegPath = getBinaryPath(ffmpegStatic);
-
✅ 路径解析正确
const ffmpegExecutable = typeof ffmpegPath === 'string' ? ffmpegPath : ffmpegPath.path;
-
✅ Spawn 使用正确
const process = spawn(ffmpegExecutable, args, { windowsHide: true });
# 启动应用
npm run dev:desktop
# 生成视频(应该不再报错)
# 选择视频片段并点击生成apps/desktop/src/main/pipeline-realtime-v2.cjs- 行 10: 添加
spawn导入 - 行 13-15: 添加 FFmpeg 路径配置
- 行 380-381: 解析可执行文件路径
- 行 384: 使用完整路径
- 行 10: 添加
apps/desktop/src/main/generator.cjs:712-760
async function runFFmpeg(args, inputFile = null, errorLogPath = null) {
return new Promise((resolve, reject) => {
const ffmpegExecutable = typeof ffmpegPath === 'string'
? ffmpegPath
: ffmpegPath.path;
// ...
const child = spawn(ffmpegExecutable, args, options);
// ...
});
}-
pipeline-realtime-v2.cjs- ✅ 已修复 -
generator.cjs- ✅ 已正确 -
pipeline-realtime.cjs- 需要检查 - 其他自定义 spawn 调用 - 需要检查
# 搜索所有直接使用 'ffmpeg' 的地方
grep -r "spawn('ffmpeg'" apps/desktop/src/main/
grep -r "execSync.*ffmpeg" apps/desktop/src/main/-
✅ 导入必要的模块
child_process的spawnffmpeg-staticgetBinaryPath工具函数
-
✅ 使用完整路径
- 解析 FFmpeg 可执行文件的完整路径
- 传递给
spawn而不是使用 'ffmpeg'
-
✅ 添加 windowsHide 选项
- 避免显示 Windows 控制台窗口
- 🎯 修复: 'ffmpeg.exe' 不是内部或外部命令错误
- 🎯 一致性: 所有模块使用相同的 FFmpeg 路径获取方式
- 🎯 可靠性: 不依赖系统 PATH,使用包管理的 FFmpeg
修复完成! 🎉
现在流水线模块可以正确找到并执行 FFmpeg 了。请重新测试生成功能。