Skip to content

Commit 0a03d39

Browse files
committed
Updated mount to support any enabled filesystems.
1 parent c95f308 commit 0a03d39

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

packages/ffmpeg/src/classes.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414
ProgressEventCallback,
1515
FileData,
1616
WorkerFSMountData,
17+
FFFSType,
18+
FFFSMountOptions,
19+
FFFSPath,
1720
} from "./types.js";
1821
import { getMessageID } from "./utils.js";
1922
import { ERROR_TERMINATED, ERROR_NOT_LOADED } from "./errors.js";
@@ -261,23 +264,23 @@ export class FFmpeg {
261264
) as Promise<OK>;
262265
};
263266

264-
public mount = (path: string, data: WorkerFSMountData): Promise<OK> => {
267+
public mount = (fsType: FFFSType, options: FFFSMountOptions, mountPoint: FFFSPath, ): Promise<OK> => {
265268
const trans: Transferable[] = [];
266269
return this.#send(
267270
{
268271
type: FFMessageType.MOUNT,
269-
data: { path, data },
272+
data: { fsType, options, mountPoint },
270273
},
271274
trans
272275
) as Promise<OK>;
273276
};
274277

275-
public unmount = (path: string): Promise<OK> => {
278+
public unmount = (mountPoint: FFFSPath): Promise<OK> => {
276279
const trans: Transferable[] = [];
277280
return this.#send(
278281
{
279282
type: FFMessageType.UNMOUNT,
280-
data: { path },
283+
data: { mountPoint },
281284
},
282285
trans
283286
) as Promise<OK>;

packages/ffmpeg/src/const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ export enum FFMessageType {
2121
LOG = "LOG",
2222
MOUNT = "MOUNT",
2323
UNMOUNT = "UNMOUNT",
24-
}
24+
}

packages/ffmpeg/src/types.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ export interface FFMessageDeleteDirData {
6464
path: FFFSPath;
6565
}
6666

67+
export enum FFFSType {
68+
MEMFS = "MEMFS",
69+
NODEFS = "NODEFS",
70+
NODERAWFS = "NODERAWFS",
71+
IDBFS = "IDBFS",
72+
WORKERFS = "WORKERFS",
73+
PROXYFS = "PROXYFS",
74+
}
75+
6776
export type WorkerFSFileEntry =
6877
| File;
6978

@@ -77,13 +86,17 @@ export interface WorkerFSMountData {
7786
files?: WorkerFSFileEntry[];
7887
}
7988

89+
export type FFFSMountOptions =
90+
| WorkerFSMountData;
91+
8092
export interface FFMessageMountData {
81-
path: FFFSPath;
82-
data: WorkerFSMountData;
93+
fsType: FFFSType;
94+
options: FFFSMountOptions;
95+
mountPoint: FFFSPath;
8396
}
8497

8598
export interface FFMessageUnmountData {
86-
path: FFFSPath;
99+
mountPoint: FFFSPath;
87100
}
88101

89102
export type FFMessageData =
@@ -158,4 +171,4 @@ export interface FFMessageEventCallback {
158171
type: string;
159172
data: CallbackData;
160173
};
161-
}
174+
}

packages/ffmpeg/src/worker.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,16 @@ const deleteDir = ({ path }: FFMessageDeleteDirData): OK => {
139139
return true;
140140
};
141141

142-
const mount = ({ path, data }: FFMessageMountData): OK => {
143-
ffmpeg.FS.mount(ffmpeg.FS.filesystems.WORKERFS, data, path);
142+
const mount = ({ fsType, options, mountPoint }: FFMessageMountData): OK => {
143+
let str = fsType as keyof typeof ffmpeg.FS.filesystems;
144+
let fs = ffmpeg.FS.filesystems[str];
145+
if (!fs) return false;
146+
ffmpeg.FS.mount(fs, options, mountPoint);
144147
return true;
145148
};
146149

147-
const unmount = ({ path }: FFMessageUnmountData): OK => {
148-
ffmpeg.FS.unmount(path);
150+
const unmount = ({ mountPoint }: FFMessageUnmountData): OK => {
151+
ffmpeg.FS.unmount(mountPoint);
149152
return true;
150153
};
151154

0 commit comments

Comments
 (0)