3
let ffmpeg = require("fluent-ffmpeg")
ffmpeg.setFfmpegPath(pathToFfmpeg)     

    var command = ffmpeg(file)

    command.on('end', function() {
        return console.log("done");
    });

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

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

    command.save(output+filename+sel);

somehow it return

Processing: undefined% done

Processing: undefined% done

Processing: undefined% done

why ? i followed the fluent-ffmpeg docs

Farrel Athaillah
  • 107
  • 1
  • 10

1 Answers1

3

(GOOGLE TRANSLATE)

It seems that in some cases ffmpeg fails to bring the percent property.

I also came across this problem and didn't find any help with it. The solution then was to make the estimate based on the total time by the current time.

The equation was as follows

(current time / total time) * 100

And the code like this:

let totalTime

ffmpeg('your_input_file_path')
   .on('start', commandLine => {
      // somenthing message for init process
    })
   .on('codecData', data => {
      // HERE YOU GET THE TOTAL TIME
      totalTime = parseInt(data.duration.replace(/:/g, '')) 
   })
   .on('progress', progress => {
      // HERE IS THE CURRENT TIME
      const time = parseInt(progress.timemark.replace(/:/g, ''))

      // AND HERE IS THE CALCULATION
      const percent = (time / totalTime) * 100
          
      console.log(percent)
    })
    .on('error', err => {
       console.log(err)
    })
    .output('your_output_file_path')
    .run()
Rubens Barbosa
  • 191
  • 1
  • 5