Skip to content

Commit ce375d9

Browse files
authored
Add classWorkerURL (#652)
1 parent 29e523b commit ce375d9

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

packages/ffmpeg/src/classes.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,19 @@ export class FFmpeg {
184184
* @returns `true` if ffmpeg core is loaded for the first time.
185185
*/
186186
public load = (
187-
config: FFMessageLoadConfig = {},
187+
{ classWorkerURL, ...config }: FFMessageLoadConfig = {},
188188
{ signal }: FFMessageOptions = {}
189189
): Promise<IsFirst> => {
190190
if (!this.#worker) {
191-
this.#worker = new Worker(new URL("./worker.js", import.meta.url), {
192-
type: "module",
193-
});
191+
this.#worker = classWorkerURL ?
192+
new Worker(new URL(classWorkerURL, import.meta.url), {
193+
type: "module",
194+
}) :
195+
// We need to duplicated the code here to enable webpack
196+
// to bundle worekr.js here.
197+
new Worker(new URL("./worker.js", import.meta.url), {
198+
type: "module",
199+
});
194200
this.#registerHandlers();
195201
}
196202
return this.#send(

packages/ffmpeg/src/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ export interface FFMessageLoadConfig {
1717
*/
1818
wasmURL?: string;
1919
/**
20-
* `ffmpeg-core.worker.js` URL.
20+
* `ffmpeg-core.worker.js` URL. This worker is spawned when using multithread version of ffmpeg-core.
2121
*
22+
* @ref: https://ffmpegwasm.netlify.app/docs/overview#architecture
2223
* @defaultValue `https://unpkg.com/@ffmpeg/core-mt@${CORE_VERSION}/dist/umd/ffmpeg-core.worker.js`;
2324
*/
2425
workerURL?: string;
26+
/**
27+
* `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.
28+
*
29+
* @ref: https://ffmpegwasm.netlify.app/docs/overview#architecture
30+
* @defaultValue `./worker.js`
31+
*/
32+
classWorkerURL?: string;
2533
}
2634

2735
export interface FFMessageExecData {

0 commit comments

Comments
 (0)