Skip to content

Add classWorkerURL #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/ffmpeg/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,19 @@ export class FFmpeg {
* @returns `true` if ffmpeg core is loaded for the first time.
*/
public load = (
config: FFMessageLoadConfig = {},
{ classWorkerURL, ...config }: FFMessageLoadConfig = {},
{ signal }: FFMessageOptions = {}
): Promise<IsFirst> => {
if (!this.#worker) {
this.#worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
});
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",
});
this.#registerHandlers();
}
return this.#send(
Expand Down
10 changes: 9 additions & 1 deletion packages/ffmpeg/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ export interface FFMessageLoadConfig {
*/
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`;
*/
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 {
Expand Down