简体   繁体   English

无法在流利的ffmpeg中使用ffprobe

[英]Unable to use ffprobe in fluent-ffmpeg

I was intended to use ffprobe function to extract video information and here is my code: 我打算使用ffprobe函数提取视频信息,这是我的代码:

var FFmpeg = require('fluent-ffmpeg');
//...
var convert_using_ffmpeg = function (source, target) {

    var tempfile = path.join(config.tmproot, path.basename(target));

    new FFmpeg({ source: source })
        .withVideoCodec('libx264')
        .withVideoBitrate('512')
        .withAudioQuality(5)
        .withAudioCodec('libmp3lame')
        .withSize('360x288')
        //.ffprobe(function(err,data) {
        //  console.dir(data);
        //})
        .toFormat('flv')
        .on('error', function (err) {
            console.log('An error occurred: ' + err.message);
        })
        .saveToFile(tempfile, function () {
            fs.rename(tempfile, target);
        });
};

The compiler simply said Object #<FfmpegCommand> has no method 'ffprobe when I execute the program. 编译器只是说我执行程序时Object #<FfmpegCommand> has no method 'ffprobe The fluent-ffmpeg API says I should add FFMPEG_PATH and FFPROBE_PATH environment variable before executing, but the fact is I could execute ffmpeg directly in command line even if it does not exist in PATH environment variable, and the node.js program runs successfully without evoking the ffprobe function. fluent-ffmpeg API表示我应该在执行之前添加FFMPEG_PATH和FFPROBE_PATH环境变量,但事实是,即使在PATH环境变量中不存在ffmpeg,我也可以直接在命令行中执行它,并且node.js程序可以成功运行而无需调用ffprobe函数。 Plus the API also says ffprobe comes together with most distribution of ffmpeg, if so, how can I add ffprobe to the environment variable separately? 另外,API还说ffprobe与ffmpeg的大多数发行版一起提供,如果是的话,如何将ffprobe分别添加到环境变量中?

I'm using fluent-ffmpeg 1.7.0 currently. 我目前正在使用fluent-ffmpeg 1.7.0。

Try setting the FFprobe path before calling it: 尝试在调用它之前设置FFprobe路径:

ffmpeg.setFfprobePath("c:\\program files\\ffmpeg\\bin\\ffprobe.exe");
ffmpeg.ffprobe(sourceFile.path, function(err, metadata) {
    if (err)
    {
        console.log(err);
    }
    else{
        console.log(metadata);
    }
});

I think the documentation you've read is actually for 2.x rather than 1.x. 我认为您阅读的文档实际上是针对2.x而非1.x的。

Try upgrading your fluent-ffmpeg module with npm install --save fluent-ffmpeg@2.0.0-rc1 尝试使用升级流利,ffmpeg的模块npm install --save fluent-ffmpeg@2.0.0-rc1

I was working on Electron project, my Node version is 10.xx, I ran into this problem and tried multiple things, finally following solved my issue: 我当时正在开发Electron项目,我的Node版本是10.xx,我遇到了这个问题并尝试了多种方法,终于解决了我的问题:

  1. After ffmpeg v4.0.0 you need to download binaries if you don't have already FF Binaries 在ffmpeg v4.0.0之后,如果您还没有FF Binaries,则需要下载二进制文件

  2. you need to set binaries path explicitly into your node project. 您需要将二进制路径明确设置为节点项目。

    const ffmpeg = require('fluent-ffmpeg');
    var ffmpegPath = require("ffmpeg-binaries");
    ffmpeg.setFfmpegPath(ffmpegPath);
    ffmpeg.setFfprobePath("D:\\sandbox\\node-proj\\binaries\\ffprobe.exe");

For ffprobe, similar should be done for other extensions 对于ffprobe,对于其他扩展名也应执行类似的操作

This way no need of ffmpeg having to be installed in os 这样一来,无需在操作系统中安装ffmpeg

const ffmpeg = require('fluent-ffmpeg');
var ffprobe = require('ffprobe-static');
ffmpeg.setFfprobePath(ffprobe.path);

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

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