Gathering detailed insights and metrics for canvas-record
Gathering detailed insights and metrics for canvas-record
Gathering detailed insights and metrics for canvas-record
Gathering detailed insights and metrics for canvas-record
canvas-capture
Record the canvas as an image, mp4 video, or gif from the browser
record-canvas
fix readme 1.2.5, adding simple recorder on index.html like example [dev]. Adding new arg options,From method to class.Save context from canvas to the mp4 video, save file can be automatic without initial click but audio context must be after first click.
canvas-recorder
Browserside tool to record canvas animations frame by frame.
@instructure/canvas-media
A component that will handle upload/record and displaying of media
npm install canvas-record
Typescript
Module System
Min. Node Version
Node Version
NPM Version
59
Supply Chain
84.4
Quality
78.2
Maintenance
100
Vulnerability
100
License
JavaScript (99.9%)
HTML (0.1%)
Total Downloads
66,645
Last Day
459
Last Week
1,923
Last Month
3,880
Last Year
51,806
330 Stars
73 Commits
18 Forks
7 Watching
3 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
5.1.0
Package Id
canvas-record@5.1.0
Unpacked Size
185.33 kB
Size
56.74 kB
File Count
32
NPM Version
10.8.1
Node Version
22.3.0
Publised On
07 Jul 2024
Cumulative downloads
Total Downloads
Last day
58.3%
459
Compared to previous day
Last week
135.7%
1,923
Compared to previous week
Last month
56.2%
3,880
Compared to previous month
Last year
422.3%
51,806
Compared to previous year
Record a video in the browser or directly on the File System from a canvas (2D/WebGL/WebGPU) as MP4, WebM, MKV, GIF, PNG/JPG Sequence using WebCodecs and Wasm when available.
1npm install canvas-record
1import { Recorder, RecorderStatus, Encoders } from "canvas-record"; 2import createCanvasContext from "canvas-context"; 3import { AVC } from "media-codecs"; 4 5// Setup 6const pixelRatio = devicePixelRatio; 7const width = 512; 8const height = 512; 9const { context, canvas } = createCanvasContext("2d", { 10 width: width * pixelRatio, 11 height: height * pixelRatio, 12 contextAttributes: { willReadFrequently: true }, 13}); 14Object.assign(canvas.style, { width: `${width}px`, height: `${height}px` }); 15 16const mainElement = document.querySelector("main"); 17mainElement.appendChild(canvas); 18 19// Animation 20let canvasRecorder; 21 22function render() { 23 const width = canvas.width; 24 const height = canvas.height; 25 26 const t = canvasRecorder.frame / canvasRecorder.frameTotal || Number.EPSILON; 27 28 context.clearRect(0, 0, width, height); 29 context.fillStyle = "red"; 30 context.fillRect(0, 0, t * width, height); 31} 32 33const tick = async () => { 34 render(); 35 36 if (canvasRecorder.status !== RecorderStatus.Recording) return; 37 await canvasRecorder.step(); 38 39 if (canvasRecorder.status !== RecorderStatus.Stopped) { 40 requestAnimationFrame(() => tick()); 41 } 42}; 43 44canvasRecorder = new Recorder(context, { 45 name: "canvas-record-example", 46 encoderOptions: { 47 codec: AVC.getCodec({ profile: "Main", level: "5.2" }), 48 }, 49}); 50 51// Start and encode frame 0 52await canvasRecorder.start(); 53 54// Animate to encode the rest 55tick(canvasRecorder);
Encoder comparison:
Encoder | Extension | Required Web API | WASM | Speed |
---|---|---|---|---|
WebCodecs | mp4 / webm / mkv | WebCodecs | ❌ | Fast |
MP4Wasm | mp4 | WebCodecs | ✅ (embed) | Fast |
H264MP4 | mp4 | ✅ (embed) | Medium | |
FFmpeg | mp4 / webm | SharedArrayBuffer | ✅ (need binary path) | Slow |
GIF | gif | WebWorkers (wip) | ❌ | Fast |
Frame | png / jpg | File System Access | ❌ | Fast |
MediaCapture | mkv / webm | MediaStream | ❌ | Realtime |
Note:
WebCodecs
encoderOptions allow different codecs to be used: VP8/VP9/AV1/HEVC. See 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.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 (ffmpeg -framerate 30 -i "%05d.jpg" -b:v 60M -r 30 -profile:v baseline -pix_fmt yuv420p -movflags +faststart output.mp4
)MP4Wasm
is embedded from mp4-wasm for ease of use (FFmpeg
will require encoderOptions.corePath
)Roadmap:
Re-export Recorder, RecorderStatus, all Encoders and utils.
boolean
Check for WebCodecs support on the current platform.
number
Estimate the bit rate of a video rounded to nearest megabit. Based on "H.264 for the rest of us" by Kush Amerasinghe.
function
A callback to notify on the status change. To compare with RecorderStatus enum values.
object
Options for recording. All optional.
object
Options for recording initialisation. All optional.
"mp4"
| "webm"
| "png"
| "jpg"
| "gif"
| "mkv"
"in-browser"
| "file-system"
object
module:@ffmpeg/ffmpeg/dist/esm/types.js~FFMessageLoadConfig
object
object
object
object
module:h264-mp4-encoder~H264MP4Encoder
object
MediaRecorderOptions
object
VideoEncoderConfig
object
VideoEncoderConfig
MuxerOptions
Re-export Recorder, RecorderStatus, all Encoders and utils.
Kind: global class
RecorderOptions
object
ArrayBuffer
| Uint8Array
| Array.<Blob>
| undefined
Create a Recorder instance
Param | Type | Default |
---|---|---|
context | RenderingContext | |
[options] | RecorderOptions | {} |
RecorderOptions
Sensible defaults for recording so that the recorder "just works".
Kind: instance property of Recorder
object
A mapping of extension to their mime types
Kind: instance property of Recorder
Start the recording by initializing and optionally calling the initial step.
Kind: instance method of Recorder
Param | Type | Default |
---|---|---|
[startOptions] | RecorderStartOptions | {} |
Encode a frame and increment the time and the playhead.
Calls await canvasRecorder.stop()
when duration is reached.
Kind: instance method of Recorder
ArrayBuffer
| Uint8Array
| Array.<Blob>
| undefined
Stop the recording and return the recorded buffer. If options.download is set, automatically start downloading the resulting file. Is called when duration is reached or manually.
Kind: instance method of Recorder
Clean up the recorder and encoder
Kind: instance method of Recorder
Kind: global class Properties
Name | Type |
---|---|
target | EncoderTarget |
extension | EncoderExtensions |
[encoderOptions] | object |
[muxerOptions] | object |
Array.<Extensions>
Array.<EncoderTarget>
ArrayBuffer
| Uint8Array
| Array.<Blob>
| undefined
Base Encoder class. All Encoders extend it and its method are called by the Recorder.
Param | Type |
---|---|
options | object |
Array.<Extensions>
The extension the encoder supports
Kind: instance property of Encoder
Array.<EncoderTarget>
The target to download the file to.
Kind: instance property of Encoder
Setup the encoder: load binary, instantiate muxers, setup file system target...
Kind: instance method of Encoder
Param | Type |
---|---|
options | object |
Encode a single frame. The frameNumber is usually used for GOP (Group Of Pictures).
Kind: instance method of Encoder
Param | Type |
---|---|
frame | number |
[frameNumber] | number |
ArrayBuffer
| Uint8Array
| Array.<Blob>
| undefined
Stop the encoding process and cleanup the temporary data.
Kind: instance method of Encoder
Clean up the encoder
Kind: instance method of Encoder
Param | Type |
---|---|
[options] | FFmpegEncoderOptions |
Param | Type |
---|---|
[options] | GIFEncoderOptions |
Param | Type |
---|---|
[options] | H264MP4EncoderOptions |
Param | Type |
---|---|
[options] | MediaCaptureEncoderOptions |
Param | Type |
---|---|
[options] | MP4WasmEncoderOptions |
Param | Type |
---|---|
[options] | WebCodecsEncoderOptions |
enum
Enum for recorder status
Kind: global enum Read only: true Example
1// Check recorder status before continuing 2if (canvasRecorder.status !== RecorderStatus.Stopped) { 3 rAFId = requestAnimationFrame(() => tick()); 4}
boolean
Check for WebCodecs support on the current platform.
number
Estimate the bit rate of a video rounded to nearest megabit. Based on "H.264 for the rest of us" by Kush Amerasinghe.
Kind: global function
Returns: number
- A bitrate value in bits per second
Param | Type | Default | Description |
---|---|---|---|
width | number | ||
height | number | ||
frameRate | number | 30 | |
motionRank | number | 4 | A factor of 1, 2 or 4 |
bitrateMode | "variable" | "constant" | variable |
Example
1// Full HD (1080p) 2const bitRate = estimateBitRate(1920, 1080, 30, "variable"); 3const bitRateMbps = bitRate * 1_000_000; // => 13 Mbps
function
A callback to notify on the status change. To compare with RecorderStatus enum values.
Kind: global typedef
Param | Type | Description |
---|---|---|
RecorderStatus | number | the status |
object
Options for recording. All optional.
Kind: global typedef Properties
Name | Type | Default | Description |
---|---|---|---|
[name] | string | """" | A name for the recorder, used as prefix for the default file name. |
[duration] | number | 10 | The recording duration in seconds. If set to Infinity, await canvasRecorder.stop() needs to be called manually. |
[frameRate] | number | 30 | The frame rate in frame per seconds. Use await canvasRecorder.step(); to go to the next frame. |
[download] | boolean | true | Automatically download the recording when duration is reached or when await canvasRecorder.stop() is manually called. |
[extension] | string | ""mp4"" | Default file extension: infers which Encoder is selected. |
[target] | string | ""in-browser"" | Default writing target: in-browser or file-system when available. |
[encoder] | object | A specific encoder. Default encoder based on options.extension: GIF > WebCodecs > H264MP4. | |
[encoderOptions] | object | See src/encoders or individual packages for a list of options. | |
[muxerOptions] | object | See "mp4-muxer" and "webm-muxer" for a list of options. | |
[onStatusChange] | onStatusChangeCb |
object
Options for recording initialisation. All optional.
Kind: global typedef Properties
Name | Type | Description |
---|---|---|
[filename] | string | Overwrite the file name completely. |
[initOnly] | boolean | Only initialised the recorder and don't call the first await recorder.step(). |
"mp4"
| "webm"
| "png"
| "jpg"
| "gif"
| "mkv"
"in-browser"
| "file-system"
object
Kind: global typedef Properties
Name | Type | Default |
---|---|---|
[encoderOptions] | FFmpegEncoderEncoderOptions | {} |
module:@ffmpeg/ffmpeg/dist/esm/types.js~FFMessageLoadConfig
Kind: global typedef See: FFmpeg#load
object
Kind: global typedef Properties
Name | Type | Default |
---|---|---|
[maxColors] | number | 256 |
[quantizeOptions] | GIFEncoderQuantizeOptions | |
[encoderOptions] | GIFEncoderEncoderOptions | {} |
object
Kind: global typedef See: QuantizeOptions Properties
Name | Type | Default |
---|---|---|
[format] | "rgb565" | "rgb444" | "rgba4444" | "rgb565" |
[oneBitAlpha] | boolean | number | false |
[clearAlpha] | boolean | true |
[clearAlphaThreshold] | number | 0 |
[clearAlphaColor] | number | 0x00 |
object
Kind: global typedef See: WriteFrameOpts Properties
Name | Type | Default |
---|---|---|
[palette] | Array.<Array.<number>> | |
[first] | boolean | false |
[transparent] | boolean | 0 |
[transparentIndex] | number | 0 |
[delay] | number | 0 |
[repeat] | number | 0 |
[dispose] | number | -1 |
object
Kind: global typedef Properties
Name | Type | Default |
---|---|---|
[debug] | boolean | |
[encoderOptions] | H264MP4EncoderEncoderOptions | {} |
module:h264-mp4-encoder~H264MP4Encoder
Kind: global typedef See: h264-mp4-encoder#api
object
Kind: global typedef Properties
Name | Type | Default |
---|---|---|
[flushFrequency] | number | 10 |
[encoderOptions] | MediaCaptureEncoderEncoderOptions | {} |
MediaRecorderOptions
Kind: global typedef See: MediaRecorder#options
object
Kind: global typedef Properties
Name | Type | Default |
---|---|---|
[groupOfPictures] | number | 20 |
[flushFrequency] | number | 10 |
[encoderOptions] | MP4WasmEncoderEncoderOptions | {} |
VideoEncoderConfig
Kind: global typedef See: VideoEncoder.configure
object
Kind: global typedef Properties
Name | Type | Default |
---|---|---|
[groupOfPictures] | number | 20 |
[flushFrequency] | number | 10 |
[encoderOptions] | WebCodecsEncoderEncoderOptions | {} |
VideoEncoderConfig
Kind: global typedef See: VideoEncoder.configure
MuxerOptions
Kind: global typedef See
All MIT:
MIT. See license file.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
0 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 0/25 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-09
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More