简体   繁体   中英

Unable to use ffprobe in fluent-ffmpeg

I was intended to use ffprobe function to extract video information and here is my code:

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. 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. 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?

I'm using fluent-ffmpeg 1.7.0 currently.

Try setting the FFprobe path before calling it:

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.

Try upgrading your fluent-ffmpeg module with 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:

  1. After ffmpeg v4.0.0 you need to download binaries if you don't have already 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

This way no need of ffmpeg having to be installed in os

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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