electron - how to use ffmpeg within an electron ap

2019-02-02 13:20发布

问题:

In the last release (v0.31.0) electron comes with a statically linked FFMpeg library (not the command line tool, see #2588)

I am aware of the many nodejs modules for ffmpeg, but they all look like an api to the command line tool, so how can I ideally access the ffmpeg library bundled with electron and encode a stream?

回答1:

This is currently not possible, since there is no decent ffmpeg library for node.js. Meaning, there are only such that abstract the CLI. However it is possible to compile and link ffmpeg as node native addon, which simply no-one seems to have done yet. So the advice, unfortunately, would be to write this kind of abstraction and include the lib into your electron build



回答2:

Disclaimer: This is a shameless plug for ffbinaries Node module and ffbinaries.com API I created.

I was looking for the answer to this a while ago and couldn't find anything useful. I decided to put something together myself and thought I'd come back here in case you still need it.

I created ffbinaries downloader to achieve this. I just started this two nights ago so might be still lacking but give it a try.

Still very much work in progress, currently (at 0.0.12) it doesn't set permissions on the file yet but it downloads the required binaries just fine.

Edit: ffbinaries has reached version 1.0.0 milestone a while back - nice, stable and it does set permissions correctly :)



回答3:

It's possible to bundle the precompiled static ffmpeg binary with an electron app; of course you'll have to make sure you bundle the correct binary with the correct distro. I have a complete answer here.