From 2a1939c7ac407ce6b5f03fc46d24a59dc39b0e39 Mon Sep 17 00:00:00 2001 From: xiaomingge1993 <87159583+xiaomingge1993@users.noreply.github.com> Date: Wed, 11 Oct 2023 22:28:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3esm=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E6=97=A0=E6=B3=95=E5=8A=A0=E8=BD=BDffmpeg-core.js?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#601)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: chenm --- packages/ffmpeg/src/worker.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/ffmpeg/src/worker.ts b/packages/ffmpeg/src/worker.ts index 1391589..f17a444 100644 --- a/packages/ffmpeg/src/worker.ts +++ b/packages/ffmpeg/src/worker.ts @@ -43,25 +43,22 @@ interface ImportedFFmpegCoreModuleFactory { let ffmpeg: FFmpegCoreModule; const load = async ({ - coreURL: _coreURL = CORE_URL, + coreURL: _coreURL, wasmURL: _wasmURL, workerURL: _workerURL, }: FFMessageLoadConfig): Promise => { const first = !ffmpeg; - const coreURL = _coreURL; - const wasmURL = _wasmURL ? _wasmURL : _coreURL.replace(/.js$/g, ".wasm"); - const workerURL = _workerURL - ? _workerURL - : _coreURL.replace(/.js$/g, ".worker.js"); try { + if (!_coreURL) _coreURL = CORE_URL; // when web worker type is `classic`. - importScripts(coreURL); + importScripts(_coreURL); } catch { + if (!_coreURL) _coreURL = CORE_URL.replace('/umd/', '/esm/'); // when web worker type is `module`. (self as WorkerGlobalScope).createFFmpegCore = ( (await import( - /* @vite-ignore */ coreURL + /* @vite-ignore */ _coreURL )) as ImportedFFmpegCoreModuleFactory ).default; @@ -70,6 +67,12 @@ const load = async ({ } } + const coreURL = _coreURL; + const wasmURL = _wasmURL ? _wasmURL : _coreURL.replace(/.js$/g, ".wasm"); + const workerURL = _workerURL + ? _workerURL + : _coreURL.replace(/.js$/g, ".worker.js"); + ffmpeg = await (self as WorkerGlobalScope).createFFmpegCore({ // Fix `Overload resolution failed.` when using multi-threaded ffmpeg-core. // Encoded wasmURL and workerURL in the URL as a hack to fix locateFile issue.