Gathering detailed insights and metrics for dcapture.js
Gathering detailed insights and metrics for dcapture.js
Gathering detailed insights and metrics for dcapture.js
Gathering detailed insights and metrics for dcapture.js
A library to capture canvas-based animations at a fixed framerate
npm install dcapture.js
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (99.74%)
Shell (0.26%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3,690 Stars
131 Commits
405 Forks
77 Watchers
6 Branches
9 Contributors
Updated on Jul 10, 2025
Latest Version
1.1.0
Package Id
dcapture.js@1.1.0
Unpacked Size
316.81 kB
Size
73.01 kB
File Count
27
NPM Version
11.2.0
Node Version
22.14.0
Published on
Mar 25, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
DCapture.js is a library to help capturing animations created with HTML5 canvas
at a fixed framerate.
DCapture.js is an updated and modernized version of the original CCapture.js library by Jaume Sanchez Elias, where "D" stands for Dmytro.
An example is probably worth a lot of words: DCapture.js with Game of Life 3D.
Let's say that you finally have your amazing canvas-based animation running in your browser, be it 2D or 3D with the power of WebGL. You've been working hard to keep it fast and smooth. If you're using requestAnimationFrame
you're aiming for a framerate of 60fps or, in other words, each frame is taking 16ms or less to render.
Now you want to record a video of it. Not a big deal, you can fire up a screen capture software that churns out a video file and be done with it. But what if you wanted to create an HD movie of your animation, and it simply cannot be rendered at higher resolutions because frames start dropping? What if you wanted to put all the quality settings up for the video? What if you wanted to push that particle count to 10 millions?
What if, indeed. What would happen is that you'd get a choppy video at best. At higher resolutions, fillrate is a bottleneck for most canvas-based animations. High quality settings or high number of elements may be only feasible on more powerful hardware.
With DCapture.js you can record smooth videos at a fixed framerate for all these situations, because it doesn't run in realtime: it makes the animations run at a given, fixed framerate which can be specified. You can record animations at smooth and consistent 30 or 60fps even if each frame takes seconds to render. You can even take a 240fps capture and create motion blur with post-production software.
The only requirement is that you step your values per frame according to elapsed time. In other words, don't increment your variables with a fixed value each frame, but use an elapsed time delta to adjust those increments. DCapture.js works by hooking the common methods for obtaining that elapsed time: Date.now()
, setTimeout
, requestAnimationFrame
, etc. and making them behave like a constant time step is happening, fixed by the specified framerate.
Methods supported so far:
Date.now
, Date.prototype.getTime
setTimeout
, clearTimeout
, setInterval
(clearInterval
pending)requestAnimationFrame
performance.now
HTMLVideoElement.prototype.currentTime
, HTMLAudioElement.prototype.currentTime
DCapture.js is more or less ryg's kkapture but for JavaScript and canvas
. It is an updated version of the original CCapture.js.
The library supports multiple export formats using modular encoders (DCFrameEncoder
):
DCWebMEncoder
uses WebM Writer for JavaScript to create a WebM movieDCPNGEncoder
and DCJPEGEncoder
export PNG and JPEG files in a TAR file, respectivelyDCGIFEncoder
uses gifjs to create animated GIFsDCFFMpegServerEncoder
uses ffmpegserver.js to generate video on the serverForks, pull requests and code critiques are welcome!
Include DCapture[.min].js and WebM Writer or gifjs.
1<script src="DCapture.min.js"></script> 2<!-- Include WebM Writer if you want to export WebM --> 3<script src="webm-writer-0.2.0.js"></script> 4<!-- Include gifjs if you want to export GIF --> 5<script src="gif.js"></script> 6<!-- Include tar.js if you want to export PNG or JPEG --> 7<script src="tar.js"></script> 8<!-- Include download.js for easier file download --> 9<script src="download.js"></script>
Or include the whole pack
1<script src="DCapture.all.min.js"></script>
Or use npm or bower to install the package:
1npm install dcapture.js
Or use bower to install the package:
1bower install dcapture.js
To create a DCapture object, write:
1// Create a capturer that exports a WebM video
2var capturer = new DCapture( { format: 'webm' } );
3
4// Create a capturer that exports an animated GIF
5// Notices you have to specify the path to the gif.worker.js
6var capturer = new DCapture( { format: 'gif', workersPath: 'js/' } );
7
8// Create a capturer that exports PNG images in a TAR file
9var capturer = new DCapture( { format: 'png' } );
10
11// Create a capturer that exports JPEG images in a TAR file
12var capturer = new DCapture( { format: 'jpg' } );
This creates a DCapture object to run at 60fps, non-verbose. You can tweak the object by setting parameters on the constructor:
1var capturer = new DCapture( {
2 framerate: 60,
3 verbose: true
4} );
The complete list of parameters is:
You can decide when to start the capturer. When you call the .start()
method, the hooks are set, so from that point on setTimeout
, setInterval
and other methods that are hooked will behave a bit differently. When you have everything ready to start capturing, and your animation loop is running, call:
1capturer.start();
requestAnimationFrame, setTimeout, etc. won't work as expected after capture is started. Make sure your animation loop is running
And then, in your render()
method, after the frame is been drawn, call .capture()
passing the canvas you want to capture.
1function render(){ 2 requestAnimationFrame(render); 3 // rendering stuff ... 4 capturer.capture( canvas ); 5} 6 7render() 8
That's all. Once you're done with the animation, you can call .stop()
and then .save()
. That will compose the video and return a URL that can be previewed or downloaded.
1capturer.stop(); 2 3// default save, will download automatically a file called {name}.extension (webm/gif/tar) 4capturer.save(); 5 6// custom save, will get a blob in the callback 7capturer.save( function( blob ) { /* ... */ } );
Note: you don't need to .stop()
in order to .save()
. Call capturer.save()
anytime you want to get a download up to that moment.
DCapture.js only works on browsers that have a `canvas implementation.
WebM Writer current version only works on a browser that supports the image/webp format. Exporting video is basically Chrome-only for now :( If you want to help to make it Firefox, Opera or even Internet Explorer compatible, please do!
gif.js has some performance limitations, be careful if capturing a lot of frames.
The autoSaveTime parameter
Different browsers have different issues with big files: most break for big Uint8Array
allocations, or when a file to downloads is larger than 1GB, etc. I haven't been able to find a solid solution for all, so I introduced the autoSaveTime
parameter, just to prevent loss of large files. If used with a webm/png/jpg capturer, it will automatically compile, download and free the captured frames every n seconds specified in the parameter. The downloaded file will have the structure {name}-part-00000n and the extension (.webm or .tar). The files inside the TAR file will have the right number of sequence.
Use an autoSaveTime
value that give you a file that is small enough to not trip the browser, but large enough to not generate a thousand part files. A value between 10 and 30 seconds for a 4K capture I've found works best: just make sure the file is under 1GB. For most regular, viewport-sized or even Full-HD captures it shouldn't be an issue, but keep in mind this issue.
Memory allocation and garbage collection
There's some issues in which memory -mostly from accumulated frames- will not be freed, depending on the platform and the mood of the browser. If you run into non-sawtooth like memory profiles, and are running chrome, try running it with --js-flags="--expose-gc"
. This way DCapture will run gc()
every frame and memory consumption should stay stable.
Big thanks to hugohil and Greggman!
MIT licensed
Copyright (C) 2012-2016 Jaume Sanchez Elias, http://www.clicktorelease.com
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 3/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
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