Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion slow with bundled ffmpeg binary #55

Closed
mh4ck opened this issue Aug 4, 2020 · 5 comments
Closed

conversion slow with bundled ffmpeg binary #55

mh4ck opened this issue Aug 4, 2020 · 5 comments
Labels

Comments

@mh4ck
Copy link

mh4ck commented Aug 4, 2020

Why is running ffmpeg from this package is more than double so slow than running the command directly on the Machine?

I can't find any solution for this.

If i run the following code it takes 35s to convert a 13min webm video to mp3.
If i run the command logged in the "start" event directly on my machine it takes only 14s

const moment = require("moment");
const ffmpegStatic = require("ffmpeg-static");
const ffmpeg = require("fluent-ffmpeg");
ffmpeg.setFfmpegPath(ffmpegStatic);

let outfile = fs.createWriteStream("music.mp3");
let infile = fs.createReadStream("video");

let startTime = moment().unix();
ffmpeg()
    .input(infile)
    .outputOptions([
        "-f mp3",
        "-vn",
        "-b:a 192k",
    ])
    .on('start', (commandLine) => {
      console.log(commandLine);
    })
    .on('error', (err, stdout, stderr) => {
        console.log(err);
    })
    .on('progress', (info) => {
        //console.log(info);
    })
    .on("end", () => {
        let endTime = moment().unix();
        console.log("Finished after " + (endTime - startTime) + "s");
    })
    .pipe(outfile);
@derhuerst
Copy link
Collaborator

If i run the command logged in the "start" event directly on my machine it takes only 14s

How do you run it? Using the same ffmpeg binary? With the same arguments?

@derhuerst
Copy link
Collaborator

derhuerst commented Aug 4, 2020

I'm just guessing here, but it might be slower because, in the Node.js process, you're reading the input file from disk and writing it to its stdout; Then, you let the ffmpeg process read it from stdin. Same with the output file, just flipped. This setup might have bottlenecks:

  • ffmpeg won't be able to seek the input file. This may be necessary to the job in a more efficient way.
  • The data has to be passed around (even copied?) several times. This may lead to a significant overhead with large files.

@mh4ck
Copy link
Author

mh4ck commented Aug 4, 2020

Hi thank you for your answer.

At first: No i haven't used the ffmpeg binary, for the console test, located in the node modules i used the local installed version.

I tried now the ffmpeg-static binary without nodejs and got the same result like with nodejs. It takes 35s.

So then is the question, why is the ffmpeg static library so slow? What is the difference and how can i speed it up?

@derhuerst derhuerst changed the title Slow conversion: Help! conversion slow with bundled ffmpeg binary Aug 4, 2020
@derhuerst
Copy link
Collaborator

So then is the question, why is the ffmpeg static library so slow? > What is the difference and how can i speed it up?

Not sure. All ffmpeg-static does is download a pre-built binary.

Before reporting this to the respective person publishing the binaries, please double-check your setup, make sure you‘re comparing the same ffmpeg versions, running in the same environment (e.g. no Docker, WSL, etc). Also, try running ffmpeg in verbose mode to find out if it uses hardware acceleration or not.

Once you‘ve confirmed a performance difference, report it with all details about your setup: OS & its version, ffmpeg version, flags used, CPUs & GPUs in your system etc.

@derhuerst
Copy link
Collaborator

I'm going to close this Issue, because it seems that I cannot fix it here in ffmpeg-static.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants