videoRecorder.d.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import type { Nullable } from "../types";
  2. import type { AbstractEngine } from "../Engines/abstractEngine";
  3. /**
  4. * This represents the different options available for the video capture.
  5. */
  6. export interface VideoRecorderOptions {
  7. /** The canvas you want to record */
  8. canvas?: HTMLCanvasElement;
  9. /** Defines the mime type of the video. */
  10. mimeType: string;
  11. /** Defines the FPS the video should be recorded at. */
  12. fps: number;
  13. /** Defines the chunk size for the recording data. */
  14. recordChunckSize: number;
  15. /** The audio tracks to attach to the recording. */
  16. audioTracks?: MediaStreamTrack[];
  17. }
  18. /**
  19. * This can help with recording videos from BabylonJS.
  20. * This is based on the available WebRTC functionalities of the browser.
  21. *
  22. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToVideo
  23. */
  24. export declare class VideoRecorder {
  25. private static readonly _DefaultOptions;
  26. /**
  27. * Returns whether or not the VideoRecorder is available in your browser.
  28. * @param engine Defines the Babylon Engine.
  29. * @param canvas Defines the canvas to record. If not provided, the engine canvas will be used.
  30. * @returns true if supported otherwise false.
  31. */
  32. static IsSupported(engine: AbstractEngine, canvas?: HTMLCanvasElement): boolean;
  33. private readonly _options;
  34. private _canvas;
  35. private _mediaRecorder;
  36. private _recordedChunks;
  37. private _fileName;
  38. private _resolve;
  39. private _reject;
  40. /**
  41. * True when a recording is already in progress.
  42. */
  43. get isRecording(): boolean;
  44. /**
  45. * Create a new VideoCapture object which can help converting what you see in Babylon to a video file.
  46. * @param engine Defines the BabylonJS Engine you wish to record.
  47. * @param options Defines options that can be used to customize the capture.
  48. */
  49. constructor(engine: AbstractEngine, options?: Partial<VideoRecorderOptions>);
  50. /**
  51. * Stops the current recording before the default capture timeout passed in the startRecording function.
  52. */
  53. stopRecording(): void;
  54. /**
  55. * Starts recording the canvas for a max duration specified in parameters.
  56. * @param fileName Defines the name of the file to be downloaded when the recording stop.
  57. * If null no automatic download will start and you can rely on the promise to get the data back.
  58. * @param maxDuration Defines the maximum recording time in seconds.
  59. * It defaults to 7 seconds. A value of zero will not stop automatically, you would need to call stopRecording manually.
  60. * @returns A promise callback at the end of the recording with the video data in Blob.
  61. */
  62. startRecording(fileName?: Nullable<string>, maxDuration?: number): Promise<Blob>;
  63. /**
  64. * Releases internal resources used during the recording.
  65. */
  66. dispose(): void;
  67. private _handleDataAvailable;
  68. private _handleError;
  69. private _handleStop;
  70. }