diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd85b93b..f7c6a3fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,6 +38,12 @@ jobs: - name: Build NapCat.Shell run: | npm i && cd napcat.webui && npm i && cd .. || exit 1 + curl -sSL https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2025-04-16-12-54/ffmpeg-n7.1.1-6-g48c0f071d4-win64-lgpl-7.1.zip -o ffmpeg.zip + unzip -q ffmpeg.zip -d ffmpeg && rm ffmpeg.zip + cd ffmpeg + mv ffmpeg.exe ../external/ffmpeg/ffmpeg.exe + mv ffprobe.exe ../external/ffmpeg/ffprobe.exe + cd .. npm run build:shell && npm run depend || exit 1 rm package-lock.json - name: Upload Artifact diff --git a/src/common/ffmpeg.ts b/src/common/ffmpeg.ts index 31ae5740..65b84473 100644 --- a/src/common/ffmpeg.ts +++ b/src/common/ffmpeg.ts @@ -1,14 +1,28 @@ import { readFileSync, statSync, existsSync, mkdirSync } from 'fs'; -import { dirname } from 'path'; +import path, { dirname } from 'path'; import { execFile } from 'child_process'; import { promisify } from 'util'; import type { VideoInfo } from './video'; import { fileTypeFromFile } from 'file-type'; import imageSize from 'image-size'; +import { fileURLToPath } from 'node:url'; +const currentPath = dirname(fileURLToPath(import.meta.url)); const execFileAsync = promisify(execFile); -const FFMPEG_CMD = process.platform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg'; -const FFPROBE_CMD = process.platform === 'win32' ? 'ffprobe.exe' : 'ffprobe'; +const getFFmpegPath = (tool: string): string => { + const exeName = `${tool}.exe`; + const isLocalExeExists = existsSync(path.join(currentPath, 'ffmpeg', exeName)); + if (process.platform === 'win32') { + return isLocalExeExists ? path.join(currentPath, 'ffmpeg', exeName) : exeName; + } + return tool; +}; + +const FFMPEG_CMD = getFFmpegPath('ffmpeg'); +const FFPROBE_CMD = getFFmpegPath('ffprobe'); + +console.log('[Info] ffmpeg:', FFMPEG_CMD); +console.log('[Info] ffprobe:', FFPROBE_CMD); export class FFmpegService { // 确保目标目录存在 private static ensureDirExists(filePath: string): void { diff --git a/vite.config.ts b/vite.config.ts index d2565857..7c8cae11 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -23,6 +23,7 @@ if (process.env.NAPCAT_BUILDSYS == 'linux') { const UniversalBaseConfigPlugin: PluginOption[] = [ cp({ targets: [ + { src: './external/ffmpeg/', dest: 'dist/ffmpeg', flatten: true }, { src: './manifest.json', dest: 'dist' }, { src: './src/core/external/napcat.json', dest: 'dist/config/' }, { src: './src/native/packet', dest: 'dist/moehoo', flatten: false }, @@ -46,6 +47,7 @@ const UniversalBaseConfigPlugin: PluginOption[] = [ const FrameworkBaseConfigPlugin: PluginOption[] = [ cp({ targets: [ + { src: './external/ffmpeg/', dest: 'dist/ffmpeg', flatten: true }, { src: './manifest.json', dest: 'dist' }, { src: './src/core/external/napcat.json', dest: 'dist/config/' }, { src: './src/native/packet', dest: 'dist/moehoo', flatten: false }, @@ -65,6 +67,7 @@ const FrameworkBaseConfigPlugin: PluginOption[] = [ const ShellBaseConfigPlugin: PluginOption[] = [ cp({ targets: [ + { src: './external/ffmpeg/', dest: 'dist/ffmpeg', flatten: true }, { src: './src/native/packet', dest: 'dist/moehoo', flatten: false }, { src: './src/native/pty', dest: 'dist/pty', flatten: false }, { src: './napcat.webui/dist/', dest: 'dist/static/', flatten: false },