fix: ffmpeg

This commit is contained in:
手瓜一十雪
2025-04-17 13:55:31 +08:00
parent dad7245a3a
commit fc37288827
3 changed files with 26 additions and 3 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 },