Skip to content

Commit 1665931

Browse files
committed
Update docs and types
1 parent 1e6f4c4 commit 1665931

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

packages/ffmpeg/src/classes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class FFmpeg {
104104
*
105105
* @example
106106
* ```ts
107-
* ffmpeg.on(FFmpeg.LOG, ({ message }) => {
107+
* ffmpeg.on("log", ({ type, message }) => {
108108
* // ...
109109
* })
110110
* ```
@@ -114,7 +114,7 @@ export class FFmpeg {
114114
*
115115
* @example
116116
* ```ts
117-
* ffmpeg.on(FFmpeg.PROGRESS, ({ progress }) => {
117+
* ffmpeg.on("progress", ({ progress, time }) => {
118118
* // ...
119119
* })
120120
* ```

packages/ffmpeg/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export interface LogEvent {
119119

120120
export interface ProgressEvent {
121121
progress: number;
122-
elapsed: number;
122+
time: number;
123123
}
124124

125125
export type ExitCode = number;

packages/types/types/index.d.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@ export type StringPointer = Pointer;
66
export type StringArrayPointer = Pointer;
77
export type DateString = string;
88

9+
/**
10+
* Options for readFile.
11+
*
12+
* @see [Emscripten File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.readFile)
13+
* @category File System
14+
*/
915
export interface ReadFileOptions {
16+
/** encoding of the file, must be `binary` or `utf8` */
1017
encdoing: string;
1118
}
1219

20+
/**
21+
* Describes attributes of a node. (a.k.a file, directory)
22+
*
23+
* @see [Emscripten File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.stat)
24+
* @category File System
25+
*/
1326
export interface Stat {
1427
dev: number;
1528
ino: number;
@@ -26,6 +39,12 @@ export interface Stat {
2639
blocks: number;
2740
}
2841

42+
/**
43+
* Functions to interact with Emscripten FS library.
44+
*
45+
* @see [Emscripten File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html)
46+
* @category File System
47+
*/
2948
export interface FS {
3049
mkdir: (path: string) => void;
3150
rmdir: (path: string) => void;
@@ -35,21 +54,42 @@ export interface FS {
3554
readdir: (path: string) => string[];
3655
unlink: (path: string) => void;
3756
stat: (path: string) => Stat;
57+
/** mode is a numeric notation of permission, @see [Numeric Notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) */
3858
isFile: (mode: number) => boolean;
59+
/** mode is a numeric notation of permission, @see [Numeric Notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) */
3960
isDir: (mode: number) => boolean;
4061
}
4162

63+
/**
64+
* Arguments passed to setLogger callback function.
65+
*/
4266
export interface Log {
67+
/** file descriptor of the log, must be `stdout` or `stderr` */
4368
type: string;
4469
message: string;
4570
}
4671

72+
/**
73+
* Arguments passed to setProgress callback function.
74+
*/
75+
export interface Progress {
76+
/** progress of the operation, interval = [0, 1] */
77+
progress: number;
78+
/** time of transcoded media in microseconds, ex: if a video is 10 seconds long, when time is 1000000 means 1 second of the video is transcoded already. */
79+
time: number;
80+
}
81+
82+
/**
83+
* FFmpeg core module, an object to interact with ffmpeg.
84+
*/
4785
export interface FFmpegCoreModule {
86+
/** default arguments prepend when running exec() */
4887
DEFAULT_ARGS: string[];
4988
FS: FS;
5089
NULL: Pointer;
5190
SIZE_I32: number;
5291

92+
/** return code of the ffmpeg exec, error when ret != 0 */
5393
ret: number;
5494
timeout: number;
5595
mainScriptUrlOrBlob: string;
@@ -58,11 +98,14 @@ export interface FFmpegCoreModule {
5898
reset: () => void;
5999
setLogger: (logger: (log: Log) => void) => void;
60100
setTimeout: (timeout: number) => void;
61-
setProgress: (handler: (progress: number, elapsed: number) => void) => void;
101+
setProgress: (handler: (progress: Progress) => void) => void;
62102

63103
locateFile: (path: string, prefix: string) => string;
64104
}
65105

106+
/**
107+
* Factory of FFmpegCoreModule.
108+
*/
66109
export type FFmpegCoreModuleFactory = (
67110
moduleOverrides?: Partial<FFmpegCoreModule>
68111
) => Promise<FFmpegCoreModule>;

src/bind/ffmpeg/bind.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ function setProgress(handler) {
7474
Module["progress"] = handler;
7575
}
7676

77-
function receiveProgress(progress, elapsed) {
78-
Module["progress"]({ progress, elapsed });
77+
function receiveProgress(progress, time) {
78+
Module["progress"]({ progress, time });
7979
}
8080

8181
function reset() {

src/fftools/ffmpeg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,8 +1505,8 @@ static void print_final_stats(int64_t total_size)
15051505
}
15061506
}
15071507

1508-
EM_JS(void, send_progress, (double progress, double elapsed), {
1509-
Module.receiveProgress(progress, elapsed);
1508+
EM_JS(void, send_progress, (double progress, double time), {
1509+
Module.receiveProgress(progress, time);
15101510
});
15111511

15121512
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)

0 commit comments

Comments
 (0)