Back to Posthog

Session replay rasterizer

nodejs/src/session-replay/recording-rasterizer/README.md

1.43.12.1 KB
Original Source

Session replay rasterizer

Temporal worker that converts session replays into MP4 videos using Puppeteer + Chromium. Runs on a dedicated rasterization-task-queue.

Architecture

text
Temporal workflow (Python)
  └─ dispatches activity to rasterization-task-queue
       └─ Node.js worker picks it up
            ├─ rasterizeRecording (Puppeteer records the replay to raw MP4)
            ├─ postProcessToMp4 (ffmpeg: strip pre-roll, trim, speed correct)
            ├─ uploadToS3
            └─ return metadata

The worker maintains a warm Chromium browser pool — a single browser instance is reused across exports and recycled after N uses.

Modules

FilePurpose
index.tsWorker entry point — launches browser pool, connects to Temporal
activities.tsTemporal activity: record → postprocess → upload → cleanup
recorder.tsPuppeteer recording logic (puppeteer-screen-recorder)
postprocess.tsffmpeg post-processing (trim, speed correction, fps)
browser-pool.tsWarm Chromium lifecycle manager
storage.tsS3 upload
config.tsEnvironment variable configuration
types.tsInput/output contracts

Two pipelines

  • User video exports: full pipeline with ffmpeg post-processing (strip pre-roll, trim to duration, apply speed correction)
  • AI/Gemini pipeline: skip_postprocessing: true — uploads raw recording directly

Running locally

bash
bin/temporal-recording-rasterizer-worker

Requires Chromium and ffmpeg installed locally.

Docker

bash
docker build -f Dockerfile.recording-rasterizer -t posthog-recording-rasterizer .

Uses Debian chromium package (not Puppeteer's bundled download).