繁体   English   中英

'ffmpeg' 在 nodejs node-ffmpeg 中不被识别为内部或外部命令

[英]'ffmpeg' is not recognized as an internal or external command in nodejs node-ffmpeg

我正在开发一个节点 js 应用程序。 首先,当谈到 Node JS 时,我只是一个初学者。 我现在在我的应用程序中所做的是我正在尝试为我的 mp4 文件创建缩略图 jpg 文件。 我已经尝试了许多可能的解决方案。 现在我正在使用这个 - https://github.com/damianociarla/node-ffmpeg 我认为这是所有潜在的解决方案。 生成视频文件的 jpg 缩略图时出现错误。 请在下面查看我到目前为止所做的工作。

我安装了运行此命令的软件包

npm install ffmpeg --save

然后我尝试生成这样的缩略图文件

var ffmpeg = require('ffmpeg');
module.exports.createVideoThumbnail = function(req, res)
{
    try {
        var process = new ffmpeg('public/lalaland.mp4');
        process.then(function (video) {

            video.fnExtractFrameToJPG('public', {
                frame_rate : 1,
                number : 5,
                file_name : 'my_frame_%t_%s'
            }, function (error, files) {
                if (!error)
                    console.log('Frames: ' + files);
                else
                    //This error message is displayed
                    console.log(error)
            });

        }, function (err) {
            console.log('Error: ' + err);
        });
    } catch (e) {
        console.log(e.code);
        console.log(e.msg);
    }
    res.json({ status : true , message: "Video thumbnail created. Hopefully" });
}

当我运行代码时,它抛出一个错误。 我在抛出错误的代码中进行了评论。 这是错误信息

{ Error: Command failed: ffmpeg -i public/lalaland.mp4 -r 1 -s 0x0 -aspect NaN:NaN -vframes 5 -filter_complex "scale=iw*sar:ih, pad=max(iw\,ih*(NaN/NaN)):ow/(NaN/NaN):(ow-iw)/2:(oh-ih)/2:black" public/my_frame_1518211962631_0x0_%d.jpg
'ffmpeg' is not recognized as an internal or external command,
operable program or batch file.

    at ChildProcess.exithandler (child_process.js:275:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
  killed: false,
  code: 1,
  signal: null,
  cmd: 'ffmpeg -i public/lalaland.mp4 -r 1 -s 0x0 -aspect NaN:NaN -vframes 5 -filter_complex "scale=iw*sar:ih, pad=max(iw\\,ih*(NaN/NaN)):ow/(NaN/NaN):(ow-iw)/2:(oh-ih)/2:black" public/my_frame_1518211962631_0x0_%d.jpg' }

我也安装了ffmg。 您可以在下面看到它是我笔记本电脑上已安装的命令

在此处输入图片说明

我的代码中缺少什么?

您是否尝试将 ffmpeg 可执行文件的路径添加到环境变量中?

也许这可以帮助其他人,因为唯一的答案不是那么清楚。

它告诉您无法识别命令 ffmpeg,这意味着您需要安装 ffmpeg 二进制文件。 您已经安装了 nodejs 库,但除此之外,您还应该安装 ffmpeg 二进制文件,它实际上将执行 JS 库调用的命令“ffmpeg”。 在此处找到下载 ffmpeg 的 url,将其解压缩并将 /bin 文件夹的路径添加到您的环境变量 (PATH) 中。

我在 Python(Jupyter Notebook)中遇到了同样的问题! 问题出在 PATH 中。 我对 Python3 的解决方案:

  1. 通过pip install ffmpegpip install ffmpeg
  2. 检查 Jupyter Notebook 中的echo %path%echo %path%
  3. 在路径中,我查找名称为C:\\ffmpeg\\bin目录,但该目录不存在
  4. 官网下载我的 Windows 10 版本并解压到目录: C:\\ffmpeg\\
  5. 然后我的echo %path%找到了ffmpeg.exe文件和代码!ffmpeg ...运行良好

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM