node.js - 在nodejs中,“ffmpeg”不被识别为内部或外部命令

标签 node.js video ffmpeg thumbnails

我正在开发一个 Node.js 应用程序。首先,我只是 Node 的初学者。

我现在在应用程序中所做的是尝试为我的 mp4 文件创建缩略图 JPEG 文件。我已经尝试过很多可能的解决方案。现在我正在使用这个 - https://github.com/damianociarla/node-ffmpeg 。我认为这是所有潜在的解决方案。当我生成视频文件的 JPEG 缩略图时出现错误。

这是我到目前为止所做的事情。我安装了运行此命令的包

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。您可以在下面看到它是我的笔记本电脑上安装的命令

enter image description here

我的代码中缺少什么?

最佳答案

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

关于node.js - 在nodejs中,“ffmpeg”不被识别为内部或外部命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48714542/

相关文章:

eclipse - 深入调试 NodeJs 源代码

Node.js MongoDB - 如何使用 Mongoose 更新多个文档?

javascript - 了解 Express Node.js 中的虚拟主机

python - 为什么我在尝试使用 ffmpeg 分割视频时会得到额外的帧

c++ - 如何让视频中的所有帧都变成 i 帧?

javascript - 递归抓取并以异步方式写入文件

html - 宽屏上 100% 宽度的视频

android ffmpeg 错误的视频输出

html - 增加视频分辨率但不增加可见尺寸

android - 使用 FFMPEG 在 Android 中合并两个音频文件