【问题标题】:How can I bundle ffmpeg in an Electron application如何在电子应用程序中捆绑 ffmpeg
【发布时间】:2018-05-30 14:59:35
【问题描述】:

我正在从 electron-webpack 样板开始构建一个 Electron 应用程序。

我找到了这个节点模块@ffmpeg-installer/ffmpeg,它将一个兼容的预编译二进制文件安装到/node_modules目录中,然后使该可执行文件的路径可以通过。

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path

这在开发过程中运行良好,但是当我构建可分发并运行它时,在尝试使用该路径生成子进程时出现错误。大概是因为路径不指向二进制。

运行分发包时路径设置如下。

/Users/me/project/dist/mac/AppName.app/Contents/Resources/app.asar/node_modules/@ffmpeg-installer/darwin-x64/ffmpeg

但是,在查看 AppName.app 包内容时,我在以下路径中找到了二进制文件。

/Users/me/project/dist/mac/AppName.app/Contents/Resources/app.asar.unpacked/node_modules/@ffmpeg-installer/darwin-x64/ffmpeg

我应该如何在使用 electron-webpackelectron-builder 的 Electron 应用程序中包含二进制依赖项?

【问题讨论】:

    标签: node.js webpack ffmpeg electron electron-builder


    【解决方案1】:

    这可能是因为 electron 会将应用程序捆绑在一个 asar 存档中(类似于 zip/tar/jar)。因此,无法解析可执行文件的路径。尝试将asar: false 传递给electron-builder(在electron-builder.json 中)。

    【讨论】:

    • 这可行,但我想知道为什么 ASAR 不工作。是不是因为默认的asarUnpack选项?
    • ⚠️ Packaging using asar archive is disabled — it is strongly not recommended. Please enable asar and use asarUnpack to unpack files that must be externally available.
    • @JoshuaBarnett 自从我遇到这个问题已经有一段时间了 - 似乎asarUnpack/smartUnpack 选项对我来说是新的。如果你能让它工作,这似乎是更好的选择——我自己不愿意使用asar: false
    【解决方案2】:

    From here:

    安装:npm i ffmpeg-static ffprobe-static

    包含在您的package.json

    build{
    ...
        "asarUnpack":[
            "node_modules/ffmpeg-static/bin/${os}/${arch}/ffmpeg",
            "node_modules/ffmpeg-static/index.js",
            "node_modules/ffmpeg-static/package.json"
            ]
        }
    

    在你的 JS 中设置路径:

    const ffmpeg = require('fluent-ffmpeg');
    
    //Get the paths to the packaged versions of the binaries we want to use
    const ffmpegPath = require('ffmpeg-static').replace(
        'app.asar',
        'app.asar.unpacked'
    );
    const ffprobePath = require('ffprobe-static').path.replace(
        'app.asar',
        'app.asar.unpacked'
    );
    
    //tell the ffmpeg package where it can find the needed binaries.
    ffmpeg.setFfmpegPath(ffmpegPath);
    ffmpeg.setFfprobePath(ffprobePath);
    

    【讨论】:

      猜你喜欢
      • 2020-12-31
      • 2015-11-24
      • 2017-02-27
      • 2015-07-09
      • 2016-02-24
      • 2017-06-26
      • 2018-05-05
      • 1970-01-01
      • 2011-08-12
      相关资源
      最近更新 更多