优化 MAC 构建配置

This commit is contained in:
YILS
2025-10-22 23:43:00 +08:00
parent 1cedfae6a7
commit 56600b3353
4 changed files with 47 additions and 13 deletions

View File

@@ -32,16 +32,7 @@ jobs:
if: matrix.os == 'macos-latest'
run: |
export ELECTRON_BUILDER_EXTRA_ARGS="--universal"
export FFMPEG_BINARIES_URL="https://cdn.npmmirror.com/binaries/ffmpeg-static"
sed -i '' 's/npm_config_arch/FFMPEG_ARCH/g' node_modules/ffmpeg-static/install.js
export FFMPEG_ARCH="x64"
npm --arch=x64 rebuild -f ffmpeg-static && mv node_modules/ffmpeg-static/ffmpeg{,-x64}
export FFMPEG_ARCH="arm64"
npm --arch=arm64 rebuild -f ffmpeg-static && mv node_modules/ffmpeg-static/ffmpeg{,-arm64}
cd node_modules/ffmpeg-static
lipo -create ffmpeg-arm64 ffmpeg-x64 -output ffmpeg
chmod 0755 ffmpeg
cd ../..
pnpm run lipo-ffmpeg
pnpm run build
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -2,7 +2,7 @@
All significant changes to this project will be recorded in this file.
此项目的所有显著更改都将记录在此文件中。
## [v1.1.8] - 2025-10-22
## [v1.1.9] - 2025-10-22
### Added
- Add MAC embedding FFmpeg support
### Fixed

View File

@@ -1,7 +1,7 @@
{
"name": "short-video-factory",
"description": "短视频工厂一键生成产品营销与泛内容短视频AI批量自动剪辑",
"version": "1.1.8",
"version": "1.1.9",
"author": {
"name": "YILS",
"developer": "YILS",
@@ -16,7 +16,8 @@
"preview": "vite preview",
"format": "prettier --write .",
"preinstall": "npx only-allow pnpm",
"postinstall": "node scripts/post-install.js"
"postinstall": "node scripts/post-install.js",
"lipo-ffmpeg":"node scripts/lipo-ffmpeg.js"
},
"dependencies": {
"axios": "^1.11.0",

42
scripts/lipo-ffmpeg.js Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env node
/**
* 1. 设置环境变量 FFMPEG_BINARIES_URL
* 2. 分别 rebuild x64 / arm64 两个架构
* 3. 用 lipo 合并为通用二进制
*/
const { execSync } = require('child_process')
const path = require('path')
// 1. 环境变量
const FFMPEG_BINARIES_URL = process.env['npm_config_ffmpeg_binaries_url']
// 2. 工具函数:执行命令并带彩色输出
function run(cmd, opts = {}) {
console.log(`\n${cmd}`)
try {
execSync(cmd, { stdio: 'inherit', shell: true, ...opts })
} catch (e) {
console.error(`❌ 命令失败: ${cmd}`)
process.exit(1)
}
}
// 3. 开始干活
const archs = ['x64', 'arm64']
const ffmpegStaticDir = path.join(__dirname, '..', 'node_modules', 'ffmpeg-static')
// rebuild 两次
archs.forEach((arch) => {
run(
`pnpm cross-env FFMPEG_BINARIES_URL=${FFMPEG_BINARIES_URL} npm --arch=${arch} rebuild -f ffmpeg-static`,
)
run(`mv ${ffmpegStaticDir}/ffmpeg ${ffmpegStaticDir}/ffmpeg-${arch}`)
})
// 合并
run('lipo -create ffmpeg-arm64 ffmpeg-x64 -output ffmpeg', { cwd: ffmpegStaticDir })
// 赋权
run('chmod 0755 ffmpeg', { cwd: ffmpegStaticDir })
console.log('\n✅ 通用 ffmpeg 已生成:', path.join(ffmpegStaticDir, 'ffmpeg'))