Add classWorkerURL (#652)

This commit is contained in:
jeromewu 2023-12-17 12:51:42 +08:00 committed by GitHub
parent 29e523bcff
commit ce375d99a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -184,11 +184,17 @@ export class FFmpeg {
* @returns `true` if ffmpeg core is loaded for the first time. * @returns `true` if ffmpeg core is loaded for the first time.
*/ */
public load = ( public load = (
config: FFMessageLoadConfig = {}, { classWorkerURL, ...config }: FFMessageLoadConfig = {},
{ signal }: FFMessageOptions = {} { signal }: FFMessageOptions = {}
): Promise<IsFirst> => { ): Promise<IsFirst> => {
if (!this.#worker) { if (!this.#worker) {
this.#worker = new Worker(new URL("./worker.js", import.meta.url), { this.#worker = classWorkerURL ?
new Worker(new URL(classWorkerURL, import.meta.url), {
type: "module",
}) :
// We need to duplicated the code here to enable webpack
// to bundle worekr.js here.
new Worker(new URL("./worker.js", import.meta.url), {
type: "module", type: "module",
}); });
this.#registerHandlers(); this.#registerHandlers();

View File

@ -17,11 +17,19 @@ export interface FFMessageLoadConfig {
*/ */
wasmURL?: string; wasmURL?: string;
/** /**
* `ffmpeg-core.worker.js` URL. * `ffmpeg-core.worker.js` URL. This worker is spawned when using multithread version of ffmpeg-core.
* *
* @ref: https://ffmpegwasm.netlify.app/docs/overview#architecture
* @defaultValue `https://unpkg.com/@ffmpeg/core-mt@${CORE_VERSION}/dist/umd/ffmpeg-core.worker.js`; * @defaultValue `https://unpkg.com/@ffmpeg/core-mt@${CORE_VERSION}/dist/umd/ffmpeg-core.worker.js`;
*/ */
workerURL?: string; workerURL?: string;
/**
* `ffmpeg.worker.js` URL. This worker is spawned when FFmpeg.load() is called, it is an essential worker and usually you don't need to update this config.
*
* @ref: https://ffmpegwasm.netlify.app/docs/overview#architecture
* @defaultValue `./worker.js`
*/
classWorkerURL?: string;
} }
export interface FFMessageExecData { export interface FFMessageExecData {