classes.d.ts 4.2 KB

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