Update docs and types

This commit is contained in:
Jerome Wu 2023-07-24 22:08:15 +08:00
parent f28681f442
commit b277631f38
5 changed files with 51 additions and 8 deletions

View File

@ -104,7 +104,7 @@ export class FFmpeg {
* *
* @example * @example
* ```ts * ```ts
* ffmpeg.on(FFmpeg.LOG, ({ message }) => { * ffmpeg.on("log", ({ type, message }) => {
* // ... * // ...
* }) * })
* ``` * ```
@ -114,7 +114,7 @@ export class FFmpeg {
* *
* @example * @example
* ```ts * ```ts
* ffmpeg.on(FFmpeg.PROGRESS, ({ progress }) => { * ffmpeg.on("progress", ({ progress, time }) => {
* // ... * // ...
* }) * })
* ``` * ```

View File

@ -119,7 +119,7 @@ export interface LogEvent {
export interface ProgressEvent { export interface ProgressEvent {
progress: number; progress: number;
elapsed: number; time: number;
} }
export type ExitCode = number; export type ExitCode = number;

View File

@ -6,10 +6,23 @@ export type StringPointer = Pointer;
export type StringArrayPointer = Pointer; export type StringArrayPointer = Pointer;
export type DateString = string; export type DateString = string;
/**
* Options for readFile.
*
* @see [Emscripten File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.readFile)
* @category File System
*/
export interface ReadFileOptions { export interface ReadFileOptions {
/** encoding of the file, must be `binary` or `utf8` */
encdoing: string; encdoing: string;
} }
/**
* Describes attributes of a node. (a.k.a file, directory)
*
* @see [Emscripten File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.stat)
* @category File System
*/
export interface Stat { export interface Stat {
dev: number; dev: number;
ino: number; ino: number;
@ -26,6 +39,12 @@ export interface Stat {
blocks: number; blocks: number;
} }
/**
* Functions to interact with Emscripten FS library.
*
* @see [Emscripten File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html)
* @category File System
*/
export interface FS { export interface FS {
mkdir: (path: string) => void; mkdir: (path: string) => void;
rmdir: (path: string) => void; rmdir: (path: string) => void;
@ -35,21 +54,42 @@ export interface FS {
readdir: (path: string) => string[]; readdir: (path: string) => string[];
unlink: (path: string) => void; unlink: (path: string) => void;
stat: (path: string) => Stat; stat: (path: string) => Stat;
/** mode is a numeric notation of permission, @see [Numeric Notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) */
isFile: (mode: number) => boolean; isFile: (mode: number) => boolean;
/** mode is a numeric notation of permission, @see [Numeric Notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) */
isDir: (mode: number) => boolean; isDir: (mode: number) => boolean;
} }
/**
* Arguments passed to setLogger callback function.
*/
export interface Log { export interface Log {
/** file descriptor of the log, must be `stdout` or `stderr` */
type: string; type: string;
message: string; message: string;
} }
/**
* Arguments passed to setProgress callback function.
*/
export interface Progress {
/** progress of the operation, interval = [0, 1] */
progress: number;
/** 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. */
time: number;
}
/**
* FFmpeg core module, an object to interact with ffmpeg.
*/
export interface FFmpegCoreModule { export interface FFmpegCoreModule {
/** default arguments prepend when running exec() */
DEFAULT_ARGS: string[]; DEFAULT_ARGS: string[];
FS: FS; FS: FS;
NULL: Pointer; NULL: Pointer;
SIZE_I32: number; SIZE_I32: number;
/** return code of the ffmpeg exec, error when ret != 0 */
ret: number; ret: number;
timeout: number; timeout: number;
mainScriptUrlOrBlob: string; mainScriptUrlOrBlob: string;
@ -58,11 +98,14 @@ export interface FFmpegCoreModule {
reset: () => void; reset: () => void;
setLogger: (logger: (log: Log) => void) => void; setLogger: (logger: (log: Log) => void) => void;
setTimeout: (timeout: number) => void; setTimeout: (timeout: number) => void;
setProgress: (handler: (progress: number, elapsed: number) => void) => void; setProgress: (handler: (progress: Progress) => void) => void;
locateFile: (path: string, prefix: string) => string; locateFile: (path: string, prefix: string) => string;
} }
/**
* Factory of FFmpegCoreModule.
*/
export type FFmpegCoreModuleFactory = ( export type FFmpegCoreModuleFactory = (
moduleOverrides?: Partial<FFmpegCoreModule> moduleOverrides?: Partial<FFmpegCoreModule>
) => Promise<FFmpegCoreModule>; ) => Promise<FFmpegCoreModule>;

View File

@ -74,8 +74,8 @@ function setProgress(handler) {
Module["progress"] = handler; Module["progress"] = handler;
} }
function receiveProgress(progress, elapsed) { function receiveProgress(progress, time) {
Module["progress"]({ progress, elapsed }); Module["progress"]({ progress, time });
} }
function reset() { function reset() {

View File

@ -1505,8 +1505,8 @@ static void print_final_stats(int64_t total_size)
} }
} }
EM_JS(void, send_progress, (double progress, double elapsed), { EM_JS(void, send_progress, (double progress, double time), {
Module.receiveProgress(progress, elapsed); Module.receiveProgress(progress, time);
}); });
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time) static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)