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

p5.webm-capture

v1.2.1

Published

A frame-by-frame capture and webm video export utility for p5.js

Downloads

7

Readme

p5js webm capture

npm version

record frame-perfect p5.js sketches to .webm format video files in the Chrome browser. handy for turning slow-developing simulation sketches into smooth animations or creating perfect-loop videos.

combination of cc-capture and webm-writer, handy for capturing frames of sketches and producing webm video output. different from other p5.recording libraries because it doesn't capture a video stream of the canvas, it captures frames individually and rebuilds them into a webm video file, so you can produce a smooth final product even if your sketch is running on a slow computer.

designed to work with p5.js and Chrome. I wrote this so I could include it on https://editor.p5js.org sketches via CDN.

it is currently available at: https://unpkg.com/[email protected]/dist/p5.webm-capture.js

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/p5.webm-capture.js"></script>
    <meta charset="utf-8" />
  </head>
  <body>
    <script>
      let c = 0;

      function setup() {
        createCanvas(400, 400);
        colorMode(HSB);
        enableCapture({
          frameCount: 360,
        });
      }

      function draw() {
        background(c, 100, 100);
        c = (c + 1) % 360;
      }
    </script>
  </body>
</html>

Usage

Include p5.webm-capture.js in your index.html page right anytime after your p5.js script tag. p5.js must be loaded before p5.webm-writer.

p5.webm-writer only has one function you need to worry about: enableCapture. It should be called from your setup() function after createCanvas.

enableCapture

Should be called in sketch setup(), after createCanvas. Prepares the webm-capture library to start grabbing frames.

Options (defaults shown in square brackets):

  • element {HTMLCanvasElement} [querySelector('canvas')] the <canvas> tag p5.js is drawing to. If you're using https://editor.p5js.org, it's usually document.getElementById("defaultCanvas0").
  • frameCount {Integer} [600] the total number of frames to capture. If you give a value less than 1, the library will run in "manual stop" mode and you'll have to call stopCapture to finish.
  • frameRate {Integer} [60] sets the frames-per-second of the final video. NOTE: this doesn't have to be the same as the frameRate of the p5.js sketch.
  • display {boolean} [false] shows a HUD style timecode view
  • onComplete {Function} [function () {}] a function that is called when capture is complete. You could use this to stop the sketch or send a message to an external process.

So a call with every option given would look like:

enableCapture({
  element: document.querySelector("canvas"),
  frameCount: 120,
  frameRate: 30,
  display: true,
  onComplete: function () {
    alert("boop!");
  },
});

By default, given no arguments, a 10 second video at 60fps will be captured and your sketch will continue running.

stopCapture

This is an optional method that can be called anytime during recording to stop capturing frames, download the recorded video, and call onComplete.

If you give a value less than 1 for frameCount, calling stopCapture() is required to stop recording and download. This is "manual stop" mode.

included libraries

I have heartily abused the following libraries to make them play nicely with esbuild:

I stripped away everything not needed for running webm exports from Chrome. You can find their source in the src/vendor folder.

hacking

Make changes, then:


$ npm run build
$ cd example
$ ./serve
$ open http://localhost:8000

Releasing a new version of the library:


# commit all changes, then
$ npm version [major|minor|patch]

Changelog

1.2.0: expose the stopCapture method and allow passing a value less than 1 to frameCount to signal the intent to stop recording manually.

1.1.0: uses p5.js library hooks so that captureFrame() is called after the draw() function automatically.

1.0.1: functioning release (like 30 minutes after 1.0.0)

1.0.0: initial release.