ccapture.js: a virtual clock, a frame wrapper, and one line inside your loop
A library to capture canvas-based animations at a fixed framerate
At a glance
- What is it?
- A rewrite of the canvas capture library onto ES modules and WebCodecs, split into a time layer and a capture layer you can use separately. The awkward parts are the p5 integration and the fact that start is called both with and without await.
- Who is it for?
- Take ccapture.js if you are rendering to a canvas and need a video at a frame rate your machine cannot draw in real time, and if you are willing to have `requestAnimationFrame`, `performance.now`, `Date`, and media `currentTime` replaced while capture runs. Check three things first.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 34 days ago.
- What is it written in?
- Mainly JavaScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 16, 2026, and from our analysis. They are not legal advice.
Star history
- spite/ccapture.js3,782 ★ · +16
| Repository | 2026-09-24 | 2026-11-16 |
|---|---|---|
| spite/ccapture.js | 3.8k | 3.8k |
16 Stars in the last 53 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The rewrite points at the repository it rewrote
The project is described as a ground-up rewrite of CCapture.js, and the link it gives for the original points at `github.com/spite/ccapture.js`, which is this repository. That is not a mistake in the link so much as a sign that the 2.x line lives under the same name and owner as the 1.x code it replaces. What changed is stated in five items: ES modules, WebCodecs, GPU motion blur, and `async`/`await`. The last two matter most in practice. WebCodecs replaces the previous encoder path, which is why the format list now includes codecs like av1 and vp9 as first-class choices rather than a single hardcoded container. The framing of the library itself is that it lies to your animation about what time it is, so an animation that renders as fast or as slowly as it needs still produces a smooth file at exactly the framerate you asked for, whether that is 30, 60 or 240. The worked case given is a 4K frame that takes two seconds to draw and still lands in a flawless 60fps file.
Time and capture are separate, and each knows nothing about the other
The architecture is three pieces and the separation is strict enough to be useful on its own. `TimeWarp` owns time: it hooks `performance.now`, `requestAnimationFrame`, `setTimeout` and `setInterval`, `Date`, and media `currentTime`, then advances a virtual clock on demand, and it knows nothing about canvases. `FrameWrap` owns capture: it takes already-drawn frames, applies motion blur, enforces the frame and time limits, and feeds a pluggable encoder, and it knows nothing about time. `CCapture` composes the two and is the recorder you use by default. The idea behind the clock is credited to ryg's kkapture, and the mechanism is that the browser's notion of time is replaced by a clock that advances exactly one fixed step per captured frame, so anything deriving motion from elapsed time steps deterministically, decoupled from wall clock. Because `requestAnimationFrame` is hooked, your loop only advances when `capture()` flushes it, which is what removes the need for any wall-clock throttle.
The one line you add, and the three things you must not do
The integration cost is a single call inside a loop you already have:
const capturer = new CCapture({ format: "mp4", framerate: 60, timeLimit: 5 });
capturer.start();
function render() {
requestAnimationFrame(render);
// draw using performance.now() (warped) or the rAF timestamp
capturer.capture(canvas);
}
render();Three constraints follow from that snippet and each one is a common way to get stuck. Set a `timeLimit` or a `frameLimit` and the recorder stops and saves itself; without one you call `capturer.stop()` and then `capturer.save()` yourself. You kick the loop once right after `start()`, or make sure it is already running, because after that `capture()` drives it. And the frame you hand to `capture()` must already be drawn, since the call is `async` and does not need to be awaited. The other half of the contract is on your motion: drive it from `performance.now()`, the rAF timestamp, or `millis()`, all of which are warped during capture, rather than incrementing a fixed amount per frame, which would make the recorded speed depend on how fast the machine drew.
p5 needs its loop taken over, and the examples disagree about await
The p5 integration is the least smooth of the three documented paths, because p5 owns its own loop. The example calls `noLoop()` and then runs a manual tick that calls `redraw()` on the warped clock and captures `document.querySelector("canvas")`, exiting when `capturer.capturing` goes false, and it re-enables the live preview from a handler registered with `capturer.on("stop", () => loop())`. That example also writes `await capturer.start()` while the introductory example writes `capturer.start()` with no await and the prose says no restructuring is needed, so the two call shapes appear side by side. three.js is the easiest case, since you pass `renderer.domElement` to `capture()` in an ordinary animate loop. Plain canvas, WebGL, and WebGPU are all the same as the top example, with one exception: GPU motion blur currently needs WebGL2, so a WebGPU source uses the CPU blur backend, which is a real cost difference rather than a caveat. Global-mode p5 users can take the UMD build instead of importing.
Options are split across the two layers by who consumes them
Every option goes to the same `CCapture` constructor, and the routing is by layer: capture options reach `FrameWrap`, timing options reach `TimeWarp`. The format list is `mp4`, `webm`, `webm-legacy`, `png`, `jpg`, and `webp`, with `mp4` the default. Framerate defaults to 60 and is the target rate of the output rather than a capture rate. Quality defaults to 90 on a 0 to 100 scale and drives both video bitrate and JPEG or WebP quality, while PNG ignores it entirely. The output filename defaults to a generated identifier rather than a fixed name, and `gifColors` defaults to 256 with a range of 2 to 256. Codec is chosen per container rather than globally, with `avc` and `vp9` as the defaults for mp4 and webm respectively and `vp9` alternatives for av1 and vp8 available. Bitrate defaults to 0, and 0 is not a literal zero, it means the value is derived from resolution times quality.
main points at source, so there is no build step to run
The manifest makes the native ES module route the primary one. `main` and `module` both point at `src/index.js`, types come from `./src/index.d.ts`, and the root export map exposes only an `import` condition, so the package ships its own source as the entry point. There are also per-piece subpath exports for `./CCapture`, `./TimeWarp`, and `./FrameWrap`, each with its own declaration file, plus a `./umd` entry pointing at the built browser bundle. The `files` array is just `src` and `build`, and `prepublishOnly` runs the build, so the UMD artefact is regenerated on publish rather than committed. The build itself is two esbuild invocations from `src/umd.js` in IIFE format targeting es2020, one plain and one minified. A UMD/IIFE global build is included for classic script use with the whole API hanging off `window.CCapture`, loadable from a CDN path that pins the major version, and the file can also be produced locally with `npm run build`.
Six node test files, a browser runner, and a types check
The test story is split three ways and the scripts make the boundaries explicit. The default `test` script is a chain of six plain node invocations with no test-runner dependency at all, one file per component: TimeWarp, FrameWrap, CCapture, WebCodecsEncoder, MotionBlur, and Modular. Alongside it, `test:browser` runs a separate script under `test/browser/` driven by `playwright-core`, which is what a WebCodecs encoder and GPU blur path would need a real browser for, and `serve` starts the matching local server script. A third script runs the TypeScript declarations through `tsc` against a fixture config under `test/types/`. The dev dependencies are three and all three are pinned to exact versions rather than ranges: esbuild at 0.24.0, playwright-core at 1.48.0, and TypeScript at 5.6.3. That exact pinning is consistent with a project that wants reproducible output from an encoder, and the repository root also carries a `CHANGELOG.md`, a `MAINTAINING.md`, a `demo/`, an `examples/` directory with a p5 example referenced from the text, and a `.nojekyll` for the GitHub Pages site.
Editorial conclusion
Take ccapture.js if you are rendering to a canvas and need a video at a frame rate your machine cannot draw in real time, and if you are willing to have `requestAnimationFrame`, `performance.now`, `Date`, and media `currentTime` replaced while capture runs. Check three things first. The library is a single 2.0.0 release dated 2026-07-27 with the branch last pushed the same day, so there is no history of fixes to read. WebGPU canvases capture fine, but GPU motion blur needs WebGL2, so a WebGPU source falls back to the CPU blur backend. And for p5 specifically, the loop has to be taken over with `noLoop()` and a manual tick, since p5 owns its own loop and the library's own p5 example resumes live preview from a `stop` handler.
Frequently asked questions
How do you install ccapture.js?
With `npm install ccapture.js`, or by pointing a script tag at the UMD build on a CDN, which exposes the whole API on `window.CCapture`. Source files are shipped as ES modules, TypeScript declarations are included, and no `@types` package is needed.
What does CCapture change about the browser clock?
TimeWarp hooks performance.now, requestAnimationFrame, setTimeout and setInterval, Date, and media currentTime, then advances a virtual clock one fixed step per captured frame. Since requestAnimationFrame is hooked, your render loop only advances when capture() flushes it.
Which formats and codecs does ccapture.js support?
Formats are mp4, webm, webm-legacy, png, jpg, and webp, with mp4 as the default. Codecs are avc, vp9, av1, and vp8, defaulting to avc for mp4 and vp9 for webm, and encoding goes through WebCodecs.
Does motion blur work with WebGPU in ccapture.js?
WebGPU canvases capture fine because WebCodecs reads them directly, but GPU motion blur currently needs WebGL2. A WebGPU source therefore falls back to the CPU blur backend, which is the main performance difference between the two.
How do I capture a p5.js sketch with ccapture.js?
p5 owns its loop, so call noLoop() and drive it yourself with a tick that calls redraw() on the warped clock and then captures the canvas. Register a stop handler to call loop() again so the live preview resumes, and global-mode users can use the UMD build with two script tags.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/spite-ccapture-js)Star history chart for your README
[](https://hysenlabs.com/projects/spite-ccapture-js)Was this useful?