解决esm模式下无法加载ffmpeg-core.js的问题 (#601)
Co-authored-by: chenm <cm@chinaliancheng.com>
This commit is contained in:
parent
147596bdb0
commit
2a1939c7ac
@ -43,25 +43,22 @@ interface ImportedFFmpegCoreModuleFactory {
|
|||||||
let ffmpeg: FFmpegCoreModule;
|
let ffmpeg: FFmpegCoreModule;
|
||||||
|
|
||||||
const load = async ({
|
const load = async ({
|
||||||
coreURL: _coreURL = CORE_URL,
|
coreURL: _coreURL,
|
||||||
wasmURL: _wasmURL,
|
wasmURL: _wasmURL,
|
||||||
workerURL: _workerURL,
|
workerURL: _workerURL,
|
||||||
}: FFMessageLoadConfig): Promise<IsFirst> => {
|
}: FFMessageLoadConfig): Promise<IsFirst> => {
|
||||||
const first = !ffmpeg;
|
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 {
|
try {
|
||||||
|
if (!_coreURL) _coreURL = CORE_URL;
|
||||||
// when web worker type is `classic`.
|
// when web worker type is `classic`.
|
||||||
importScripts(coreURL);
|
importScripts(_coreURL);
|
||||||
} catch {
|
} catch {
|
||||||
|
if (!_coreURL) _coreURL = CORE_URL.replace('/umd/', '/esm/');
|
||||||
// when web worker type is `module`.
|
// when web worker type is `module`.
|
||||||
(self as WorkerGlobalScope).createFFmpegCore = (
|
(self as WorkerGlobalScope).createFFmpegCore = (
|
||||||
(await import(
|
(await import(
|
||||||
/* @vite-ignore */ coreURL
|
/* @vite-ignore */ _coreURL
|
||||||
)) as ImportedFFmpegCoreModuleFactory
|
)) as ImportedFFmpegCoreModuleFactory
|
||||||
).default;
|
).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({
|
ffmpeg = await (self as WorkerGlobalScope).createFFmpegCore({
|
||||||
// Fix `Overload resolution failed.` when using multi-threaded ffmpeg-core.
|
// Fix `Overload resolution failed.` when using multi-threaded ffmpeg-core.
|
||||||
// Encoded wasmURL and workerURL in the URL as a hack to fix locateFile issue.
|
// Encoded wasmURL and workerURL in the URL as a hack to fix locateFile issue.
|
||||||
|
Loading…
Reference in New Issue
Block a user