File size: 5,114 Bytes
cf8de4b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | import { FSNode, FFMessageLoadConfig, OK, IsFirst, LogEventCallback, ProgressEventCallback, FileData, FFFSType, FFFSMountOptions, FFFSPath } from "./types.js";
type FFMessageOptions = {
signal?: AbortSignal;
};
/**
* Provides APIs to interact with ffmpeg web worker.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* ```
*/
export declare class FFmpeg {
#private;
loaded: boolean;
/**
* Listen to log or prgress events from `ffmpeg.exec()`.
*
* @example
* ```ts
* ffmpeg.on("log", ({ type, message }) => {
* // ...
* })
* ```
*
* @example
* ```ts
* ffmpeg.on("progress", ({ progress, time }) => {
* // ...
* })
* ```
*
* @remarks
* - log includes output to stdout and stderr.
* - The progress events are accurate only when the length of
* input and output video/audio file are the same.
*
* @category FFmpeg
*/
on(event: "log", callback: LogEventCallback): void;
on(event: "progress", callback: ProgressEventCallback): void;
/**
* Unlisten to log or progress events from `ffmpeg.exec()`.
*
* @category FFmpeg
*/
off(event: "log", callback: LogEventCallback): void;
off(event: "progress", callback: ProgressEventCallback): void;
/**
* Loads ffmpeg-core inside web worker. It is required to call this method first
* as it initializes WebAssembly and other essential variables.
*
* @category FFmpeg
* @returns `true` if ffmpeg core is loaded for the first time.
*/
load: ({ classWorkerURL, ...config }?: FFMessageLoadConfig, { signal }?: FFMessageOptions) => Promise<IsFirst>;
/**
* Execute ffmpeg command.
*
* @remarks
* To avoid common I/O issues, ["-nostdin", "-y"] are prepended to the args
* by default.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* await ffmpeg.load();
* await ffmpeg.writeFile("video.avi", ...);
* // ffmpeg -i video.avi video.mp4
* await ffmpeg.exec(["-i", "video.avi", "video.mp4"]);
* const data = ffmpeg.readFile("video.mp4");
* ```
*
* @returns `0` if no error, `!= 0` if timeout (1) or error.
* @category FFmpeg
*/
exec: (args: string[], timeout?: number, { signal }?: FFMessageOptions) => Promise<number>;
/**
* Execute ffprobe command.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* await ffmpeg.load();
* await ffmpeg.writeFile("video.avi", ...);
* // Getting duration of a video in seconds: ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.avi -o output.txt
* await ffmpeg.ffprobe(["-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", "video.avi", "-o", "output.txt"]);
* const data = ffmpeg.readFile("output.txt");
* ```
*
* @returns `0` if no error, `!= 0` if timeout (1) or error.
* @category FFmpeg
*/
ffprobe: (args: string[], timeout?: number, { signal }?: FFMessageOptions) => Promise<number>;
/**
* Terminate all ongoing API calls and terminate web worker.
* `FFmpeg.load()` must be called again before calling any other APIs.
*
* @category FFmpeg
*/
terminate: () => void;
/**
* Write data to ffmpeg.wasm.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* await ffmpeg.load();
* await ffmpeg.writeFile("video.avi", await fetchFile("../video.avi"));
* await ffmpeg.writeFile("text.txt", "hello world");
* ```
*
* @category File System
*/
writeFile: (path: string, data: FileData, { signal }?: FFMessageOptions) => Promise<OK>;
mount: (fsType: FFFSType, options: FFFSMountOptions, mountPoint: FFFSPath) => Promise<OK>;
unmount: (mountPoint: FFFSPath) => Promise<OK>;
/**
* Read data from ffmpeg.wasm.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* await ffmpeg.load();
* const data = await ffmpeg.readFile("video.mp4");
* ```
*
* @category File System
*/
readFile: (path: string, encoding?: string, { signal }?: FFMessageOptions) => Promise<FileData>;
/**
* Delete a file.
*
* @category File System
*/
deleteFile: (path: string, { signal }?: FFMessageOptions) => Promise<OK>;
/**
* Rename a file or directory.
*
* @category File System
*/
rename: (oldPath: string, newPath: string, { signal }?: FFMessageOptions) => Promise<OK>;
/**
* Create a directory.
*
* @category File System
*/
createDir: (path: string, { signal }?: FFMessageOptions) => Promise<OK>;
/**
* List directory contents.
*
* @category File System
*/
listDir: (path: string, { signal }?: FFMessageOptions) => Promise<FSNode[]>;
/**
* Delete an empty directory.
*
* @category File System
*/
deleteDir: (path: string, { signal }?: FFMessageOptions) => Promise<OK>;
}
export {};
|