Skip to content

Commit

Permalink
feat: add initOnly option to startOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnsgn committed Apr 20, 2023
1 parent 8f956ed commit 69e0ab1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const tick = async () => {
canvasRecorder = new Recorder(context, {
name: "canvas-record-example",
encoderOptions: {
codec: AVC.getCodec({ name: "High", level: "5.2" }),
codec: AVC.getCodec({ profile: "Main", level: "5.2" }),
},
});

Expand All @@ -100,6 +100,7 @@ Encoder comparison:

Note:

- WebCodecs encoderOptions allow different codecs to be used: VP8/VP9/AV1/HEVC. See [media-codecs](https://github.com/dmnsgn/media-codecs) to get a codec string from human readable options and check which ones are supported in your browser with [github.io/media-codecs](https://dmnsgn.github.io/media-codecs/).
- WebCodecs 5-10x faster than H264MP4Encoder and 20x faster than FFmpeg (it needs to mux files after writing png to virtual FS)
- FFmpeg (mp4 and webm) and WebCodecs (mp4) have a AVC maximum frame size of 9437184 pixels. That's fine until a bit more than 4K 16:9 @ 30fps. So if you need 4K Square or 8K exports, be patient with H264MP4Encoder (which probably also has the 4GB memory limit) or use Frame encoder and mux them manually with FFmpeg CLI.
- MP4Wasm is embedded from [mp4-wasm](https://github.com/mattdesl/mp4-wasm/) for ease of use (FFmpeg will require `encoderOptions.corePath`)
Expand Down
7 changes: 4 additions & 3 deletions src/Recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const RecorderStatus = Object.freeze({
/**
* @typedef {Object} RecorderStartOptions Options for recording. All optional.
* @property {string} [filename] Overwrite the file name completely.
* @property {boolean} [initOnly] Only initialised the recorder and don't call the first await recorder.step().
*/

/**
Expand Down Expand Up @@ -228,10 +229,10 @@ Speedup: x${(this.time / renderTime).toFixed(3)}`,
}

/**
* Start the recording by initializing and calling the initial step.
* Start the recording by initializing and optionally calling the initial step.
* @param {RecorderStartOptions} startOptions
*/
async start(startOptions) {
async start(startOptions = {}) {
await this.init(startOptions);

// Ensure initializing worked
Expand All @@ -242,7 +243,7 @@ Speedup: x${(this.time / renderTime).toFixed(3)}`,

this.#updateStatus(RecorderStatus.Recording);

await this.step();
if (!startOptions.initOnly) await this.step();
}

/**
Expand Down

0 comments on commit 69e0ab1

Please sign in to comment.