/** * ffmpeg x11grab recorder with NVIDIA NVENC hardware encoder. * * Captures the Xvfb virtual display directly with `ffmpeg -f x11grab` at a * fixed framerate, encoded straight to MP4 via `h264_nvenc` running on the * Cloud Run NVIDIA L4 GPU. Decouples clip recording from Chromium's * compositor speed AND from the CPU JPEG encoder that capped the previous * CDP `Page.captureScreenshot` path at ~9 fps. * * Why this works on Cloud Run when v1.3.10 (libx264) didn't: * - v1.3.10 used CPU encoder (libx264) which competed with Chromium for * vCPU on the same machine, giving 1.83 fps. * - h264_nvenc offloads the entire encode to dedicated NVIDIA NVENC silicon * on the L4 (separate from CUDA cores). Encode is essentially free CPU-side. * - The L4 has 2× NVENC blocks and can sustain multiple 4K streams in * parallel, so 1440x900@30fps is trivial. * * Lifecycle: one recorder instance per BEGIN_CLIP/END_CLIP. Xvfb itself * runs for the whole browser process lifetime. * * Refs: * - https://docs.cloud.google.com/run/docs/tutorials/video-encoding * - https://docs.nvidia.com/video-technologies/video-codec-sdk/13.0/ffmpeg-with-nvidia-gpu/index.html */ export interface FfmpegX11RecorderOptions { /** DISPLAY string (e.g. `:99`). */ display: string; /** Capture region width in pixels. Should match Xvfb screen width. */ width: number; /** Capture region height in pixels. Should match Xvfb screen height. */ height: number; /** Target framerate. */ fps: number; /** Absolute path to the output .mp4 file. */ outputPath: string; } export interface FfmpegX11RecorderResult { outputPath: string; trimStartMs: number; durationMs: number; } export declare class FfmpegX11Recorder { private readonly opts; private process; private startedAt; private firstFrameAt; private lastReportedFrameLine; private stderrTail; constructor(opts: FfmpegX11RecorderOptions); start(): Promise; stop(): Promise; }