Skip to content

droserasprout/perfect-canvas

Repository files navigation

Perfect Canvas

This is a Firefox extension to accurately capture WebGL canvas content. It's designed for algorave/visual programming tools like Hydra and Cables.gl, but should work with any WebGL canvas.

Screenshot of Perfect Canvas in action

Features

  • Pixel-perfect frame-by-frame capture.
  • Configurable resolution, FPS, quality (CRF), and encoder speed (preset).
  • Codec choice: libx264 (CPU, default), h264_vaapi (GPU, AMD/Intel) or h264_nvenc (GPU, Nvidia).
  • Automatic canvas resize to match capture resolution (restored after).
  • Hydra, Cables.gl, and Strudel support: patches requestAnimationFrame / performance.now so output is frame-perfect regardless of real render speed.
  • Optional per-frame timing dump to ~/.cache/perfect-canvas/profile-<ts>.log for profiling (with mean/stddev/min/p50/p95/max summary).

Requirements

  • Firefox browser on Linux. Other systems not tested.
  • Python 3.10+ with websockets package.
  • ffmpeg installed and available in PATH.

Installation

# 0. Clone this repository
git clone https://github.com/droserasprout/perfect-canvas.git

# 1. Install `ffmpeg` and `python-websockets` depending on your OS:

# - Debian/Ubuntu:
sudo apt install ffmpeg python3-websockets
# - Fedora:
sudo dnf install ffmpeg python3-websockets
# - Arch:
sudo pacman -S ffmpeg python-websockets

# 2. Install native component
cd native
sh ./install.sh

# 3. Open `about:debugging` in Firefox, click "Load Temporary Add-on", and select `manifest.json` in the project root.

Performance

Test settings: 1080x1920, 10s, 60fps, CRF=18, preset=ultrafast, /tmp write

setup project real FPS
Ryzen 7 4800HS, Firefox 140 Strudel+Hydra, fat project 33
Ryzen 7 4800HS, Firefox 140 Hydra, basic example 47
Ryzen 7 4800HS, Firefox 140 cables.gl 19
Ryzen 7 4800HS, Hellfire 142 cables.gl 22
Ryzen 7 4800HS, Nightly 142 cables.gl 22
RTX 2060 Max-Q, Nightly 142 cables.gl 26
RTX 2060 Max-Q, Nightly 142 Hydra, basic example 41

Roadmap

  • Publish on AMO
  • Bug: FPS affects speed, probably in Strudel only
  • Progress bar in popup UI (rendering speed after capture is already shown)
  • Timeout if no frames are received after some time. Currently just hangs until reload
  • Fix Strudel support; addon doesn't slow down rendering
  • Option to select canvas if multiple are present
  • Add audio capture support (tricky, but possible)

About

Frame-perfect WebGL canvas capture to FFmpeg

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors