Javascript electron app中未定义ffmpeg的元数据
我正确安装了ffmpeg,我可以通过在cmd中写入Javascript electron app中未定义ffmpeg的元数据,javascript,ffmpeg,electron,Javascript,Ffmpeg,Electron,我正确安装了ffmpeg,我可以通过在cmd中写入ffmpeg来检查它,这会给我这个结果 现在,在我的index.html中的electron应用程序中,我从用户处获取输入,并将自定义事件发送到位于index.js入口点的应用程序的electron端 index.html <script> const electron = require('electron'); const { ipcRenderer } = electron; document.que
ffmpeg
来检查它,这会给我这个结果
现在,在我的index.html中的electron应用程序中,我从用户处获取输入,并将自定义事件发送到位于index.js入口点的应用程序的electron端
index.html
<script>
const electron = require('electron');
const { ipcRenderer } = electron;
document.querySelector('form').addEventListener('submit', (e) => {
e.preventDefault();
const { path } = document.querySelector('input').files[0];
ipcRenderer.send('video:submit', path);
});
</script>
当我取消注释console.log(metadata.format.duration)
typeError:无法读取属性
未定义的“格式”
我做错了什么
因此,我设置了两个新的环境变量,现在在我控制台.log时发生了另一个错误(错误):
(我不得不将其粘贴为代码,因为它说我的帖子包含格式不正确的代码)好吧,感谢@Alexander Leithner,我找到了答案。所以错误是我的环境变量,应该是:
- ffmeg_路径,路径值为ffmeg.exe
- FFPROBE_路径,路径值为FFPROBE.exe
- 值为C的路径:…。\ffmpeg\bin
err
中),这就是元数据
未定义的原因。尝试记录错误
。哦,当然。。我有错误:找不到ffprobeThe状态Windows用户必须将ffmpeg可执行文件添加到他们的%PATH
变量中。因此,您必须将其添加到%PATH
或设置%FFMPEG\u路径
和/或%FFPROBE\u路径
环境变量。我使用一些cmd命令只指定了%PATH%,%FFMPEG\u路径和%FFPROBE\u路径应该具有哪些值?是的,在Windows中使用Electron可能会很痛苦。
const electron = require('electron');
const ffmpeg = require('fluent-ffmpeg');
const { app, BrowserWindow, ipcMain } = electron;
app.on('ready', () => {
const mainWindow = new BrowserWindow({});
mainWindow.loadURL(`file://${__dirname}/index.html`);
});
ipcMain.on('video:submit', (event, path) => {
ffmpeg.ffprobe(path, (err, metadata) => {
console.log(metadata);
//console.log(metadata.format.duration);
});
});
{ Error: spawn C:\Users\Borys\Documents\videoinfo\ffmpeg\bin ENOENT
at exports._errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn C:\\Users\\Borys\\Documents\\videoinfo\\ffmpeg\\bin',
path: 'C:\\Users\\Borys\\Documents\\videoinfo\\ffmpeg\\bin',
spawnargs:
[ '-show_streams',
'-show_format',
'C:\\Users\\Borys\\Documents\\portfolio\\img\\header_video.mp4' ] }`