fix(canvas): 视频合并 - 改用同源 FFmpeg 资源避免自部署加载失败

Fixes #168
This commit is contained in:
ddCat
2026-08-07 16:30:27 +08:00
parent 44c7d48271
commit 31ce749a6f
3 changed files with 14 additions and 6 deletions

View File

@@ -8,6 +8,7 @@
"@ant-design/icons": "^6.3.2",
"@codemirror/lang-json": "^6.0.2",
"@excalidraw/excalidraw": "0.18.1",
"@ffmpeg/core": "0.12.10",
"@ffmpeg/ffmpeg": "^0.12.15",
"@ffmpeg/util": "^0.12.2",
"@mediapipe/tasks-vision": "^1.0.1",
@@ -207,6 +208,8 @@
"@excalidraw/random-username": ["@excalidraw/random-username@1.1.0", "", {}, "sha512-nULYsQxkWHnbmHvcs+efMkJ4/9TtvNyFeLyHdeGxW0zHs6P+jYVqcRff9A6Vq9w9JXeDRnRh2VKvTtS19GW2qA=="],
"@ffmpeg/core": ["@ffmpeg/core@0.12.10", "", {}, "sha512-dzNplnn2Nxle2c2i2rrDhqcB19q9cglCkWnoMTDN9Q9l3PvdjZWd1HfSPjCNWc/p8Q3CT+Es9fWOR0UhAeYQZA=="],
"@ffmpeg/ffmpeg": ["@ffmpeg/ffmpeg@0.12.15", "", { "dependencies": { "@ffmpeg/types": "^0.12.4" } }, "sha512-1C8Obr4GsN3xw+/1Ww6PFM84wSQAGsdoTuTWPOj2OizsRDLT4CXTaVjPhkw6ARyDus1B9X/L2LiXHqYYsGnRFw=="],
"@ffmpeg/types": ["@ffmpeg/types@0.12.4", "", {}, "sha512-k9vJQNBGTxE5AhYDtOYR5rO5fKsspbg51gbcwtbkw2lCdoIILzklulcjJfIDwrtn7XhDeF2M+THwJ2FGrLeV6A=="],

View File

@@ -16,6 +16,7 @@
"@ant-design/icons": "^6.3.2",
"@codemirror/lang-json": "^6.0.2",
"@excalidraw/excalidraw": "0.18.1",
"@ffmpeg/core": "0.12.10",
"@ffmpeg/ffmpeg": "^0.12.15",
"@ffmpeg/util": "^0.12.2",
"@mediapipe/tasks-vision": "^1.0.1",

View File

@@ -1,5 +1,7 @@
import { FFmpeg } from "@ffmpeg/ffmpeg";
import { fetchFile, toBlobURL } from "@ffmpeg/util";
import ffmpegCoreURL from "@ffmpeg/core?url";
import ffmpegWasmURL from "@ffmpeg/core/wasm?url";
import { fetchFile } from "@ffmpeg/util";
import { getMediaBlob } from "@/services/file-storage";
export type MergeVideoInput = { id: string; url?: string; storageKey?: string };
@@ -12,12 +14,14 @@ async function loadFFmpeg(onProgress?: (progress: MergeVideoProgress) => void) {
if (!ffmpegPromise) {
ffmpegPromise = (async () => {
const ffmpeg = new FFmpeg();
const baseURL = "https://unpkg.com/@ffmpeg/core@0.12.10/dist/umd";
onProgress?.({ phase: "loading", progress: 0 });
await ffmpeg.load({
coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"),
wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, "application/wasm"),
});
try {
// 核心资产随前端同源发布,避免自部署环境首次合并依赖第三方 CDN。
await ffmpeg.load({ coreURL: ffmpegCoreURL, wasmURL: ffmpegWasmURL });
} catch (cause) {
ffmpeg.terminate();
throw new Error("视频合并工具加载失败,请刷新页面后重试", { cause });
}
return ffmpeg;
})();
}