1、安装fluent-ffmpeg @ffmpeg-installer/ffmpeg @ffprobe-installer/ffprobe
2、启动报错

Can’t resolve ‘./lib-cov/fluent-ffmpeg’
找到报错位置fluent-ffmpeg/index.js
设置配置process.env.FLUENTFFMPEG_COV的值为false
可通过patch-package打补丁

patch-package fluent-ffmpeg

也可通过webpack.EnvironmentPlugin设置

plugins: [
		new webpack.EnvironmentPlugin({
			FLUENTFFMPEG_COV: false,
		}),
	],
3、编译报错

Cannot find module 'D:\code\works\kemi\kemi-livestream\node_modules@ffmpeg-installer\win32-x64\package.json

解决方式:使用ffmpeg-static-electron和ffprobe-static-electron
不再用@ffmpeg-installer/ffmpeg @ffprobe-installer/ffprobe这来个包
并配置externals

externals: {
 	'ffmpeg-static-electron': 'commonjs2 ffmpeg-static-electron',
    'ffprobe-static-electron': 'commonjs2 ffprobe-static-electron',
}
4、electron-build打包

由于这俩个包未进行编译,所以需要将这俩个包打到electron编译包里导入使用
1、将node-modules里面这俩个包编译到electron包里
配置build,我放在了dist目录下

"extraResources": [
            "static/",
            {
                "from": "dist/node_modules/",
                "to": "node_modules/"
            }
        ],
        "files": [
            "build/**/*",
            "dist/*",
            "app/stream/cmdModulesPath.js"
        ],

2、使用"ffmpeg-static-electron": 和 "ffprobe-static-electron"来获取正确的路径

const ffmpegPath = require('ffmpeg-static-electron');
const ffprobePath = require('ffprobe-static-electron');

const cmdModulesPath =  {
    ffmpegPath: ffmpegPath.path,
    ffprobePath: ffprobePath.path,
}

module.exports = cmdModulesPath;
Logo

音视频技术社区,一个全球开发者共同探讨、分享、学习音视频技术的平台,加入我们,与全球开发者一起创造更加优秀的音视频产品!

更多推荐