Gathering detailed insights and metrics for canvas-recorder
Gathering detailed insights and metrics for canvas-recorder
Gathering detailed insights and metrics for canvas-recorder
Gathering detailed insights and metrics for canvas-recorder
@webav/av-recorder
Record MediaStream to MP4, Use Webcodecs API encode VideoFrame and AudioData, [mp4box.js](https://github.com/gpac/mp4box.js) as muxer. 录制 MediaStream 到 MP4,使用 Webcodecs API 编码 VideoFrame、AudioData,mp4box.js 封装。
@webav/av-canvas
Combine Text, Image, Video, Audio, UserMedia, DisplayMedia to generate MediaStream. With [AVRcorder](../av-recorder/README.md) you can output MP4 streams and save them as local files or push them to the server.
@tawaship/canvas-recorder
Save the canvas on the web page as a video.
canvas-app-recorder
Record application using canvas and webaudio
npm install canvas-recorder
Typescript
Module System
Node Version
NPM Version
60.2
Supply Chain
96.1
Quality
74.7
Maintenance
100
Vulnerability
98.9
License
TypeScript (89.47%)
JavaScript (9.03%)
HTML (1.51%)
Total Downloads
7,044
Last Day
1
Last Week
8
Last Month
20
Last Year
673
39 Stars
69 Commits
6 Forks
3 Watching
17 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
1.8.0
Package Id
canvas-recorder@1.8.0
Unpacked Size
37.00 kB
Size
10.19 kB
File Count
11
NPM Version
6.3.0
Node Version
10.8.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
8
Compared to previous week
Last month
-53.5%
20
Compared to previous month
Last year
-39.9%
673
Compared to previous year
4
A blatant ripoff of Looper 😎
This is a small utility to record a canvas based animation of any sort. The tool can be used to run the animation in the browser until one is ready to record it. The setup works around four core methods depicted in the code below:
1import { options, start, draw, getCanvas } from "canvas-recorder"; 2 3options( { 4 size: [ 500, 500 ], 5 frames: 30 6} ); 7 8draw( ( context, delta ) => { 9 10 // ... Do something here 11 12} ); 13 14document.body.appendChild( getCanvas() ); 15 16start();
Additionally, canvas-recorder
can also be used as a command line tool to merge the image sequence into
a MP4 file format. See here
Note: The package is written in Typescript and ships with types. Use in JS or TS alike.
options( settings: {} )
draw( ( context, time ) => {} )
start()
stop()
setup( ( context ) => {} )
cleanup( () => {} )
getCanvas(): HTMLCanvasElement
getContext(): CanvasRenderingContext2D
bootstrap( options?: {} )
Recorder
addFrame( canvas: HTMLCanvasElement ): Promise
getBundle(): JSZip
downloadBundle(): Promise
options( settings: {} )
Used to set settings for the recording. In most cases calling options will be done before any frames are recorded as a
first step of the program. Calling options while in between start()
and stop()
(while it is recording) calls is not
permitted.
It takes one argument which is an object with the following possible settings:
record
: [Default: true
] Enables/Disables the recording of all frames. Setting this to false
is useful in
development. Not recording any frames significantly speeds up the drawing cycles.clear
: [Default: false
] Clears the previous frame on every draw call.,size
: [Default: [1024, 1024]
] Sets the size of the canvas.frames
: [Default: -1
] Determines the amount of frames recorded. If set to -1
it will continue recording until
a call to stop()
.onComplete
: [Default <internal>
] Function that is called when all frames are recorded and archived into a zip in
form of a Blob
. When not set, a download is triggered automatically.color
: [Default: "white"
] Sets the background color of every frame if clear
is set to true
.fps
: [Default: 60
] The framerate from which the elapsed time is calculated in record mode. Note that the
recording won't happen in at this pace as it is no longer realtime.canvas
: [Default: HTMLCanvasElement
] Allows to use a specific canvas element for recording instead of creating
an internal one.draw( ( context, time ) => {} )
The draw method is the heart of the recorder. It takes on argument which is a callback. This callback will recieve two arguments at every invocation:
context
which is a CanvasRenderingContext2D
associated with the Canvas. This context is generally used to draw
the frame.time
is the amount of milliseconds since the most recent start
call. Using this time
argument allows for the
async recording to adhere to the animations fluidity. Do not calculate the time yourself, as the recording process is
much slower than the desired framerate.start()
Calling this will start the loop of the recorder.
stop()
Will terminate the loop. If the settings are set to record: true
, calling stop
will subsequently finalize all
recorded frames and compress them in a ZIP archive. By default this ZIP will trigger a download to save all frames,
unless onComplete
is set with a costum function. If so, said function will recieve the ZIP in form of a Blob
.
setup( ( context ) => {} )
This method will be called right before the frist draw call. The context is passed. This is especially useful in the WebGL implementation.
cleanup( () => {} )
This is a utility that can be used as a callback after the recording has terminated. This is especially useful when the recorder is used in frame mode. After the desired amount of frames this method will be called. Once this method is called all resources can be used freely and won't no longer be used by the recorder.
getCanvas(): HTMLCanvasElement
Returns the canvas being used by the recorder.
getContext(): CanvasRenderingContext2D
Returns the context attached to the canvas of the recorder.
bootstrap( options? )
Shorthand for inserting the canvas into the DOM as well as calling start()
. This is particularly useful
for short sketches.
Bootstrapping allows an options paramter. An object that has a single flag clear
. Calling
boostrap( { clear: true } )
will terminate previous sketch and remove the previous canvas from
the DOM. This is helpful when one has an auto-reload with a undefined loop. By default bootstrap()
does not clear.
Recorder
All methods are simply a shorthand for an instance of a Recorder
. If one would rather instantiate the recorder
themselves, maybe to run multiple recorders at once, do it like so:
1import { Recorder } from "canvas-recorder"; 2 3const recorder = new Recorder(); 4 5recorder.options( { 6 ... 7} ); 8 9recorder.draw( ( context: CanvasRenderingContext2D, time: number ) => { 10 ... 11} ); 12 13recorder.start();
addFrame( canvas: HTMLCanvasElement ): Promise
In order to use the frame packaging without any of the utility methods listed above, one can use addFrame
and the
following methods to aggregate all frames manually. This me adds an PNG of the current frame to the bundle.
One can add as many frames as one likes. Use the following methods to retrive the ZIP or download it.
getBundle(): JSZip
Returns the current bundle as a zip containing all frames. See JSZip Documentation for how to use it.
downloadBundle(): Promise
Downloads the current set of frames and resets the bundle. This is useful if you want to download lots of frames
and don't want the zip to get too large. After calling download the next call to addFrame
will be in a new bundle.
The following example shows how to use it without all helper methods.
1import { addFrame, downloadBundle } from "canvas-recorder"; 2 3// ... canvas setup 4 5context.fillStyle = "green"; 6context.fillRect( 10, 14, 200, 300 ); 7 8addFrame( canvas ).then( () => { 9 downloadBundle(); 10} );
The package is also avialble with webgl support. The API is quasi identical. In order to use it as a WebGL package change the import slightly
1import triangle from "a-big-triangle"; 2import createShader from "gl-shader"; 3import { options, start, draw, getCanvas, setup } from "canvas-recorder/gl"; 4 5let shader; 6 7options( { 8 frames: 10, 9 size: [ 100, 100 ] 10} ); 11 12setup( ( gl: WebGLRenderingContext ) => { 13 shader = createShader( 14 gl, 15 ` 16 precision mediump float; 17 attribute vec2 position; 18 19 varying vec2 uv; 20 21 void main() { 22 uv = position.xy; 23 gl_Position = vec4( position.xy, 0.0, 1.0 ); 24 } 25 `, 26 ` 27 precision mediump float; 28 varying vec2 uv; 29 void main() { 30 gl_FragColor = vec4( 1, 0, 0, 1 ); 31 } 32 `, 33 ); 34} ); 35 36draw( ( gl: WebGLRenderingContext ) => { 37 38 shader.bind(); 39 40 triangle( gl ); 41} ); 42 43start();
In this implementation, the context is always a WebGLRenderingContext
instead of a CanvasRenderingContext2D
.
Tool to turn the image sequence into a movei format.
When installed globally, or through the use of a package.json, one can invoke the command canvas-recorder
or
alternatively use the alias ffmpy
(pronounced: effeffempey) as a shorter command.
Unsurprisingly uses FFmpeg under the hood. It has a limited amount of possible options but sets defaults for all of them. Therefore the easiest usecase is calling the command in the directory of the image sequence with not flags
-i, --input <dir>
Path to the folder of the image sequence. Defaults to .
.-r, --fps <num>
Framerate used in the movie file. Defaults to 30
.-o, --output <name>
File name of the output. Defaults to out.mp4
.When installed globally, the commands are available everywhere. Alternatively, when installed locally in the project it can still be executed from the package.json
1"scripts": { 2 "merge": "canvas-recorder -i ./image-sequence/ -o film.mp4" 3}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/23 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
Reason
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
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