Skip to content

Commit 2a1939c

Browse files
xiaomingge1993chenm
andauthored
解决esm模式下无法加载ffmpeg-core.js的问题 (#601)
Co-authored-by: chenm <[email protected]>
1 parent 147596b commit 2a1939c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/ffmpeg/src/worker.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,22 @@ interface ImportedFFmpegCoreModuleFactory {
4343
let ffmpeg: FFmpegCoreModule;
4444

4545
const load = async ({
46-
coreURL: _coreURL = CORE_URL,
46+
coreURL: _coreURL,
4747
wasmURL: _wasmURL,
4848
workerURL: _workerURL,
4949
}: FFMessageLoadConfig): Promise<IsFirst> => {
5050
const first = !ffmpeg;
51-
const coreURL = _coreURL;
52-
const wasmURL = _wasmURL ? _wasmURL : _coreURL.replace(/.js$/g, ".wasm");
53-
const workerURL = _workerURL
54-
? _workerURL
55-
: _coreURL.replace(/.js$/g, ".worker.js");
5651

5752
try {
53+
if (!_coreURL) _coreURL = CORE_URL;
5854
// when web worker type is `classic`.
59-
importScripts(coreURL);
55+
importScripts(_coreURL);
6056
} catch {
57+
if (!_coreURL) _coreURL = CORE_URL.replace('/umd/', '/esm/');
6158
// when web worker type is `module`.
6259
(self as WorkerGlobalScope).createFFmpegCore = (
6360
(await import(
64-
/* @vite-ignore */ coreURL
61+
/* @vite-ignore */ _coreURL
6562
)) as ImportedFFmpegCoreModuleFactory
6663
).default;
6764

@@ -70,6 +67,12 @@ const load = async ({
7067
}
7168
}
7269

70+
const coreURL = _coreURL;
71+
const wasmURL = _wasmURL ? _wasmURL : _coreURL.replace(/.js$/g, ".wasm");
72+
const workerURL = _workerURL
73+
? _workerURL
74+
: _coreURL.replace(/.js$/g, ".worker.js");
75+
7376
ffmpeg = await (self as WorkerGlobalScope).createFFmpegCore({
7477
// Fix `Overload resolution failed.` when using multi-threaded ffmpeg-core.
7578
// Encoded wasmURL and workerURL in the URL as a hack to fix locateFile issue.

0 commit comments

Comments
 (0)