npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

recordable-canvas

v0.1.1

Published

A canvas element that can be recorded to a downloadable video

Downloads

1

Readme

recordable-canvas

A canvas element that can be recorded to a downloadable video

<recordable-canvas> is a Web Component that wraps the canvas element and provides an API to record the contents of the canvas to an MP4 file.

It uses the Web Codecs API (https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API) to encode the stream, and then MP4Box.js (https://github.com/gpac/mp4box.js/) to mux and save the file.

Since the canvas has a limited API (as most operations are done through the canvas context, you should find all the methods you'd normally need on an HTMLCanvasElement passed through.

In addition to any normal canvas attributes, a recording attribute will be applied when this component is recording. There are also few more API calls:

Use by importing index.js or recordable-canvas.js and wait for the ready event to set up the canvas (otherwise the component may not have registered yet and not have an API)

<recordable-canvas width="300" height="300"></recordable-canvas>
<script>
    import 'recordable-canvas';
    const canvas = document.body.querySelector('recordable-canvas');
    canvas.addEventListener('ready', () => { ...
</script>

get innerCanvas

as the canvas we're recording against is wrapped with the recordable-canvas Web Component, if you need to access this canvas for any reason, you may do so with this getter

startRecording

Start canvas recording. This accepts two optional arguments:

  • timeBetweenKeyframes: if you want to change the default time in milliseconds (1000) between keyframes in the encoded video, you may set this here
  • config: a custom VideoEncoderConfig you may pass to override the default (specified below)

Default Encoder Configuration:

{
    codec : 'avc1.42001E',
    width: 0,
    height: 0,
    hardwareAcceleration:"prefer-hardware",
    avc:{format:"avc"}
}

width and height will be overwritten with the canvas width and height

avc1.42001E refers to AVC baseline level 3 which supports 1920x1080 as shown in the demos in this repo. Refer here for others https://privacycheck.sec.lrz.de/active/fp_cpt/fp_can_play_type.html

stopRecording

Stops recording the canvas. Accepts an optional string for a filename. If the filename is specified, the file will automatically be saved as a download

saveFile

Accepts a filename as a parameter and when calls, saves the file as a download

get isRecording

A getter which will return true or false to indicate if recording is in progress

encodeFrame

Pass with no arguments. This will snapshot the current state of the canvas and encode it. Recordings occur in realtime, meaning the frame's timestamp will be relative to the "startRecording" call measured by your system's time. For example, if you call encodeFrame 3 seconds after you start recording, that timestamp will be 3 seconds in the video.

This will also return the current duration of the video in MICROseconds (to match the internal timestamp of the frame).


Using without the Web Component

The Web Component API mainly serves as a wrapper for the canvasrecorder.js class. Most of the API is the same with the exception of needing to pass the canvas where needed.

get isRecording

A getter which will return true or false to indicate if recording is in progress

get recordingDuration

A getter which will return the duration in milliseconds of your current recording

startRecording

Start canvas recording. One required and two optional arguments are accepted:

  • canvas: The canvas element being recorded
  • timeBetweenKeyframes: if you want to change the default time in milliseconds (1000) between keyframes in the encoded video, you may set this here
  • config: a custom VideoEncoderConfig you may pass to override the default (specified below)

stopRecording

Stops recording the canvas. Accepts an optional string for a filename. If the filename is specified, the file will automatically be saved as a download

saveFile

Accepts a filename as a parameter and when calls, saves the file as a download

encode

  • canvas: The canvas element being recorded at the time you wish to snapshot it Recordings occur in realtime, meaning the frame's timestamp will be relative to the "startRecording" call measured by your system's time. For example, if you call encode 3 seconds after you start recording, that timestamp will be 3 seconds in the video.

This will also return the current duration of the video in MICROseconds (to match the internal timestamp of the frame).