fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.94k stars 880 forks source link

Consecutive fluent-ffmpeg commands cannot view progress #979

Open TechnoTew opened 4 years ago

TechnoTew commented 4 years ago

Version information

Code to reproduce

const proceed = new Promise((resolve, reject) => {
                var command = ffmpeg(audioStream)
                .audioBitrate('256')
                //.audioCodec('copy')
                .saveToFile(`${__dirname}/../../MusicFiles/${videoDownloadQueue.videos[0].title}.mp3`)
                .on('progress', (p) => {
                    if (p.targetSize >= 1024) {
                        newMessage.edit(`Audio Download Progress: ${(p.targetSize/1024).toFixed(2)} MB downloaded\nCurrent Speed: ${(p.targetSize / ((Date.now() - start) / 1000)).toFixed(2)} KB/s`);
                    } else {
                        newMessage.edit(`Audio Download Progress: ${p.targetSize} KB downloaded\nCurrent Speed: ${(p.targetSize / ((Date.now() - start) / 1000)).toFixed(2)} KB/s`);
                    }
                })
                .on('error', (err) => {
                    console.log(err);
                    reject();
                })
                .on('end', () => {
                    //new

                    ffmpeg(videoStream)
                    .addInput(`${__dirname}/../../MusicFiles/${videoDownloadQueue.videos[0].title}.mp3`)
                    .saveToFile(`${__dirname}/../../VideoFiles/${videoDownloadQueue.videos[0].title}.mp4`)
                    .on('error', (err) => {
                        console.log(err);
                        reject();
                    })
                    .on('progress', (p) => {
                        console.log(p.targetSize);
                        if (p.targetSize >= 1024) {
                            newMessage.edit(`Video Download Progress: ${(p.targetSize/1024).toFixed(2)} MB downloaded\nCurrent Speed: ${(p.targetSize / ((Date.now() - start) / 1000)).toFixed(2)} KB/s`);
                        } else {
                            newMessage.edit(`Video Download Progress: ${p.targetSize} KB downloaded\nCurrent Speed: ${(p.targetSize / ((Date.now() - start) / 1000)).toFixed(2)} KB/s`);
                        }
                    })
                    .on('end', () => {
                        resolve();
                    });

                    //new
                    //resolve();
                })
            });
await proceed

(note: if the problem only happens with some inputs, include a link to such an input file)

Expected results

Message changing based on progress, both progress being shown

Observed results

Only the audio download progress is shown

1c7 commented 4 years ago

Same here! Please fix this.

After some reading on the issue board, turn out this project need maintainer, this project currently is in "low maintain mode" which is understandable, base on this Wiki

1c7 commented 4 years ago

This example work fine

var ffmpeg = require('../lib/fluent-ffmpeg');

function run1() {
    var file_path = '/Users/remote_edit/Desktop/fluent-ffmpeg2/examples/test.mp4'
    var command = ffmpeg(file_path);
    command.audioCodec('libmp3lame')
        .videoCodec('libx264')
        .videoBitrate(1000)
        .size('640x480')
        .on('progress', function (progress) {
            console.log('First video: ' + progress.percent + '% done');
        })
        .on('end', function (progress) {
            run2();
        })
        .save('./First.mp4')
}

function run2() {
    console.log('run2 get run');
    var file_path = '/Users/remote_edit/Desktop/fluent-ffmpeg2/examples/test.mp4'
    var command = ffmpeg(file_path);
    command.audioCodec('libmp3lame')
        .videoCodec('libx264')
        .videoBitrate(1000)
        .size('640x480')
        .on('progress', function (progress) {
            console.log('Second video: ' + progress.percent + '% done');
        })
        .on('end', function (progress) {
            console.log('done');
        })
        .save('./Second.mp4')
}

run1();
1c7 commented 4 years ago

image

It's weird, in this example code, it works fine

but in my production code (an Electron.js Desktop App) it has this "progress not correct" issue

1c7 commented 4 years ago

My env

1c7 commented 4 years ago

I found out what's going on. here is fluent-ffmpeg working correctly:

image

.save() should be the last, here is the right way to do it

image

1c7 commented 4 years ago

This is wrong way to do it

image

1c7 commented 4 years ago

@TechnoTew I think in your case, saveToFile should be the last one.

This probably works, you can try it, I haven't

image

Seblor commented 7 months ago

I can confirm this is still a thing, the .save method must be called after the .on methods in the chain