From ce2ccd5b9692c491c10201d9d4a56d5b0e78ac14 Mon Sep 17 00:00:00 2001 From: yizhi <946185759@qq.com> Date: Wed, 26 Mar 2025 19:13:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95ffmpeg=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{build_ffmpeg_win.js => build_ffmpeg.js} | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) rename thirdpart/{build_ffmpeg_win.js => build_ffmpeg.js} (82%) diff --git a/thirdpart/build_ffmpeg_win.js b/thirdpart/build_ffmpeg.js similarity index 82% rename from thirdpart/build_ffmpeg_win.js rename to thirdpart/build_ffmpeg.js index 9299adc..415cefd 100644 --- a/thirdpart/build_ffmpeg_win.js +++ b/thirdpart/build_ffmpeg.js @@ -8,6 +8,8 @@ const FFMPEG_TAG = "release/7.1" const FFMPEG_SOURCE_DIR = path.join(__dirname, "_source/FFmpeg"); const FFMPEG_INSTALL_DIR = path.join(__dirname, "FFmpeg"); +const isWindows = os.platform() == "win32"; + function checkEnv() { if (!process.env.MSYSTEM_PREFIX) throw new Error("Please use msys2 environment to run this script"); const bash = process.env.SHELL; @@ -26,14 +28,17 @@ function build() { //configure if (!fs.existsSync(path.join(FFMPEG_SOURCE_DIR, "ffbuild/config.mak"))) { console.log("Configuring ffmpeg..."); - if (0 != spawnSync(process.env.SHELL, [ - path.join(FFMPEG_SOURCE_DIR, "configure"), + const args = [ `--prefix=${FFMPEG_INSTALL_DIR}`, "--enable-static", "--enable-small", "--toolchain=msvc", "--disable-programs", - ], { stdio: "inherit", cwd: FFMPEG_SOURCE_DIR }).status) throw new Error("Failed to configure ffmpeg"); + ]; + const configureFile = path.join(FFMPEG_SOURCE_DIR, "configure"); + if (isWindows) args.unshift(configureFile); + + if (0 != spawnSync(isWindows ? process.env.SHELL : configureFile, args, { stdio: "inherit", cwd: FFMPEG_SOURCE_DIR }).status) throw new Error("Failed to configure ffmpeg"); } //make if (0 != spawnSync("make", [ @@ -51,7 +56,7 @@ function resolve() { for (const file of fs.readdirSync(path.join(FFMPEG_INSTALL_DIR, "lib"))) { if (path.extname(file) == ".a") { const libName = file.replace(/\.a$/, "").replace(/^lib/, ""); - fs.renameSync(path.join(FFMPEG_INSTALL_DIR, "lib", file), path.join(FFMPEG_INSTALL_DIR, "lib", libName + ".lib")); + if (isWindows) fs.renameSync(path.join(FFMPEG_INSTALL_DIR, "lib", file), path.join(FFMPEG_INSTALL_DIR, "lib", libName + ".lib")); libs.push(libName); } } @@ -68,7 +73,7 @@ async function main() { fs.mkdirSync(path.dirname(FFMPEG_SOURCE_DIR), { recursive: true }); fs.mkdirSync(path.dirname(FFMPEG_INSTALL_DIR), { recursive: true }); - checkEnv(); + if (isWindows) checkEnv(); if (!fs.existsSync(path.join(FFMPEG_SOURCE_DIR, "configure"))) download(); if (!fs.existsSync(path.join(FFMPEG_INSTALL_DIR, "config.cmake"))) {