node-fluent-ffmpeg: info.percent returns undefined

Hello, i have this code, i want to show the percentage of the conversion `

    var infs = fs.createReadStream(path);
    var self = this;
    var command = ffmpeg(infs);

    command.on('end', function() {
        return cb(null);
    });

    command.on('error', function() {
        return cb(err);
    });

    command.on('progress', function(info) {
         console.log('progress ' + info.percent + '%');
    });

    command.save(dest);`

and it show undefined in the console: ‘progress undefined%’

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

I too get progress undefined% when doing this:

var ffmpeg = require('fluent-ffmpeg')

var proc = ffmpeg('C:\\Users\\ErraticFox\\Desktop\\me.mp4')

  .on('progress', function(info) {
  console.log('progress ' + info.percent + '%');
  })

  .on('end', function() {
    console.log('file has been converted succesfully');
  })

  .on('error', function(err) {
    console.log('an error happened: ' + err.message);
  })

  .save('C:\\Users\\ErraticFox\\Desktop\\output.mp3');

What am I doing wrong?

calculating percentage uses ffprobe, if you have installed ffmpeg via node-ffmpeg-installer, you should install node-ffprobe-installer too

Follow the prompts to solve this problem.

import * as ffmpeg from 'fluent-ffmpeg';
import * as ffmpegInstaller from '@ffmpeg-installer/ffmpeg';
import * as ffmpegProbe from '@ffprobe-installer/ffprobe';
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
ffmpeg.setFfprobePath(ffmpegProbe.path);

I too get progress undefined% when doing this:

var ffmpeg = require('fluent-ffmpeg')

var proc = ffmpeg('C:\\Users\\ErraticFox\\Desktop\\me.mp4')

  .on('progress', function(info) {
  console.log('progress ' + info.percent + '%');
  })

  .on('end', function() {
    console.log('file has been converted succesfully');
  })

  .on('error', function(err) {
    console.log('an error happened: ' + err.message);
  })

  .save('C:\\Users\\ErraticFox\\Desktop\\output.mp3');

What am I doing wrong?

use .output(out_path) instead of save, and add .run() to the chain

calculating percentage uses ffprobe, if you have installed ffmpeg via node-ffmpeg-installer, you should install node-ffprobe-installer too

UPDATE: So I got it to work, somewhat.

This is how I’m showing the percentage. Unfortunately, this only works when converting to mp3. Any reason why this is?

        .on('stderr', function(line) {
            var res = inputDir.split(" ")

            if (line.trim().startsWith('Duration')) {
                var match = line.trim().match(/Duration:\s\d\d\:\d\d:\d\d/).toString().split('Duration:').slice(1).toString().split(':');
                duration = +match[0] * 60 * 60 + +match[1] * 60 + +match[2];
            } else if (line.trim().startsWith('size=')) {
                match = line.trim().match(/time=\d\d\:\d\d:\d\d/).toString().split('time=').slice(1).toString().split(':');
                var seconds = +match[0] * 60 * 60 + +match[1] * 60 + +match[2];
                percent = seconds / duration;
                percent = (percent * 100).toFixed()
                $('#percent').html(percent + '%')
                $('.determinate').css('width', percent + '%')
                console.log(`stderr: ${line}`)
                console.log(`${percent}%`)
            }
        })