Demo: ESModule Mode (Source: /example) | UMD Mode
This is a simple tool to capture frames from a p5.js sketch and save them into your local file system.
It is useful for creating animations or exporting frames for further processing.\
[!WARNING] This package uses File System Access API, so it is only available in Chromium-based browsers.
- Include following script in your p5.js sketch:
<script src="https://cdn.jsdelivr.net/npm/p5-frame-capturer/dist/umd.js"></script>
- Install the package:
npm install p5-frame-capturer
- Import the package in your p5.js sketch:
import { attachCapturerUi } from 'p5-frame-capturer';
import p5 from 'p5';
const p = new p5((sketch) => /* ... */);
attachCapturerUi(p);
Entire api is exported as a global variable window.p5FrameCapturer
, or use ESModule import.
List of supported image formats.
png
jpeg
webp
webpLossless
[!NOTE]
webpLossless
uses wasm-based encoder, so it might be slower than other formats.
Attaches the frame capturer UI to the p5.js sketch. On UMD build, this function is automatically called.
Starts capturing frames from the p5.js sketch.
-
format
: Image format to save the frames. Default:png
. -
frames
: Number of frames to capture. You can useundefined
or0
to capture frames indefinitely untilstopCapturing()
is called. Default:undefined
. -
parallelWriteLimit
: Maximum number of frames to write in parallel. You can use0
to remove the limit, but this may cause your browser to crash. Default:8
. -
onFinished
: Callback function to call when capturing is finished. Will not be called ifframes
isundefined
. Default:undefined
.
Stops capturing frames.
Current state of the capturer.
-
isCapturing
: Whether the capturer is capturing frames. -
frameCount
: Number of frames captured so far. -
frames
: Number of frames to capture, or0
if capturing indefinitely. -
fps
: Frames captured per second.
- You can use
onEnd
callback and ntfy.sh to get a notification when capturing is finished.
startCapturer(p, {
onFinished: () =>
fetch("https://ntfy.sh/your_topic_name", {
method: "POST",
body: "All frames are captured!",
// This line is required to avoid CORS error
mode: "no-cors",
}),
});
This project is licensed under the MIT License - see the LICENSE file for details.
The WebP encoder is built with Rust. The licenses of used crates are available in the NOTICE.md file.