Installations
npm install canvas-recorder
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
10.8.0
NPM Version
6.3.0
Score
60.2
Supply Chain
96.1
Quality
74.7
Maintenance
100
Vulnerability
98.9
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (89.47%)
JavaScript (9.03%)
HTML (1.51%)
Developer
MathiasPaumgarten
Download Statistics
Total Downloads
7,044
Last Day
1
Last Week
8
Last Month
20
Last Year
673
GitHub Statistics
39 Stars
69 Commits
6 Forks
3 Watching
17 Branches
2 Contributors
Bundle Size
171.15 kB
Minified
53.99 kB
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
7,044
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
Canvas Recorder
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.
- Methods
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
- WebGL
- Cli Tool
Methods
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 tofalse
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 tostop()
.onComplete
: [Default<internal>
] Function that is called when all frames are recorded and archived into a zip in form of aBlob
. When not set, a download is triggered automatically.color
: [Default:"white"
] Sets the background color of every frame ifclear
is set totrue
.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 aCanvasRenderingContext2D
associated with the Canvas. This context is generally used to draw the frame.time
is the amount of milliseconds since the most recentstart
call. Using thistime
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} );
WebGL
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();
Context
In this implementation, the context is always a WebGLRenderingContext
instead of a CanvasRenderingContext2D
.
Cli Tool
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
Flags
-i, --input <dir>
Path to the folder of the image sequence. Defaults to.
.-r, --fps <num>
Framerate used in the movie file. Defaults to30
.-o, --output <name>
File name of the output. Defaults toout.mp4
.
Setup
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Reason
64 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-wg6g-ppvx-927h
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-j4f2-536g-r55m
- Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-jg8v-48h5-wgxg
- Warn: Project is vulnerable to: GHSA-36fh-84j7-cv5h
- Warn: Project is vulnerable to: GHSA-7x7c-qm48-pq9c
- Warn: Project is vulnerable to: GHSA-rc3x-jf5g-xvc5
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-82v2-mx6x-wq7q
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-fxwf-4rqh-v8g3
- Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj
- Warn: Project is vulnerable to: GHSA-xfhh-g9f5-x4m4
- Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq
- Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-mgfv-m47x-4wqp
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5
- Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
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 MoreOther packages similar to 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