npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ffmpeg-static-electron-forge

v1.1.7

Published

This module is designed for fast integration with electron forge and webpack.

Downloads

78

Readme

ffmpeg-static-electron-forge

This package provides an easy and quick integration of FFmpeg with electron-forge and webpack. It's lightweight and does not affect production, and it's very easy to use. Thank you for using this package!

Installation

To install the package, run the following command in your project:

  npm install ffmpeg-static-electron-forge

The library detects your operating system and downloads the binaries, but you can set env var ALL_BINS=true flag to download all of them for Windows, Linux, Mac, which is approximately 250MB. You can also use your own optimized or customized binaries by creating a bin folder in node_modules/ffmpeg-static-electron-forge, and make sure that the operating system directories match os.platform() and the architecture matches os.arch().

Linux, Mac

  export ALL_BINS=true
  npm install ffmpeg-static-electron-forge

Windows

  $env:ALL_BINS="true"
  npm install ffmpeg-static-electron-forge

Usage

To use the package, simply add ffmpeg-static-electron-forge to your development dependencies. Once installed, you can access FFmpeg from your electron-forge configuration. It's important to set asar: true in packagerConfig.

const path = require("path");
const FFmpegStatic = require("ffmpeg-static-electron-forge").default;

module.exports = {
  packagerConfig: {
    asar: true, // Important
  },
  rebuildConfig: {},
  makers: [
    {
      name: "@electron-forge/maker-squirrel",
      config: {},
    },
    {
      name: "@electron-forge/maker-zip",
      platforms: ["darwin"],
    },
    {
      name: "@electron-forge/maker-deb",
      config: {},
    },
    {
      name: "@electron-forge/maker-rpm",
      config: {},
    },
  ],
  plugins: [
    {
      name: "@electron-forge/plugin-webpack",
      config: {
        mainConfig: "./webpack.main.config.js",
        renderer: {
          config: "./webpack.renderer.config.js",
          entryPoints: [
            {
              html: "./src/index.html",
              js: "./src/renderer.js",
              name: "main_window",
              preload: {
                js: "./src/preload.js",
              },
            },
          ],
        },
      },
    },
    new FFmpegStatic({
      remove: true, // Required
      path: path.join(__dirname, ".webpack", "main"), // Set path of main build
    }),
  ],
};
import ffmpeg from "fluent-ffmpeg";
import { paths } from "ffmpeg-static-electron-forge";

const ffmpegPath = paths.ffmpegPath.replace("app.asar", "app.asar.unpacked");
const ffprobePath = paths.ffprobePath.replace("app.asar", "app.asar.unpacked");

ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg.setFfprobePath(ffprobePath);

export default ffmpeg;

Known errors

The first error that is not from this package, if not from fluent-ffmpeg is when doing a make to the application, this error is easily fixable by changing in the index.js in the node_modules folder this code.

This needs to be changed:

module.exports = process.env.FLUENTFFMPEG_COV ? require('./lib-cov/fluent-ffmpeg') : require('./lib/fluent-ffmpeg');

for this

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

or explicitly set the environment variable process.env.FLUENTFFMPEG_COV to false

Another error is that in development mode the binaries are not found.

the latest version of this package solves this problem and here is an example of how to export ffmpeg for development and production.

NOTE: this example works whether you are using ES Modules or require.

import { paths, bins } from "ffmpeg-static-electron-forge";
import ffmpeg from "fluent-ffmpeg";
import path from "path";

let ffmpegPath: string, ffprobePath: string;

if (process.env.NODE_ENV !== "development") {
  ffmpegPath = paths.ffmpegPath.replace("app.asar", "app.asar.unpacked");
  ffprobePath = paths.ffprobePath.replace("app.asar", "app.asar.unpacked");
} else {
  let ffmpegBinPaths = path.dirname(
    require.resolve("ffmpeg-static-electron-forge")
  );
  ffmpegBinPaths = path.resolve(process.cwd(), ffmpegBinPaths, "bin");
  ffmpegPath = path.join(ffmpegBinPaths, bins.ffmpegPath);
  ffprobePath = path.join(ffmpegBinPaths, bins.ffprobePath);
}

ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg.setFfprobePath(ffprobePath);

for older versions you will have to manually copy the path to the binaries and use them while they are under development.

X:\MyApp\node_modules\ffmpeg-static-electron-forge\dist\bin\win32\x64\ffmpeg.exe
X:\MyApp\node_modules\ffmpeg-static-electron-forge\dist\bin\win32\x64\ffprobe.exe

Contributions

If you find any issues or have any suggestions to improve this package, please create an issue on our GitHub repository. If you want to contribute with code, please fork the repository and create a pull request with your changes.

License

This project is licensed under the MIT license. You can read the full license in the LICENSE file.