Client Real-Shot Screen Recording (With Audio)
Positioning: Delivery-grade demo video production line. Not "just a screenshot," but a real client running state + real mouse & keyboard operations + audible sound triple combo.
Trigger & Execute
When the user expresses intent like "record a video / real-shot demo / screen recording for me / make a demo video / with audio" and the target is a WorkLoom repository (containing apps/desktop/electron/main.cjs), execute according to this skill.
Act 0 · Select Recording Route (Critical Decision)
| Content Type | Route | Reason |
|---|---|---|
| 2D page operation demo (click button/fill form/navigate) | Route A: Real-time Screen Recording (x11grab, Act 3) | Operation flow is the star, real-time suffices |
| 3D scene / CSS animation / ceremonial | Route B: Offline Frame-by-Frame Rendering (this act) | Sandbox has no GPU, uses CPU software rendering; real-time recording would be choppy—choppiness is an environment issue, but we must fix it, not let the client guess |
Route B · Virtual Clock Offline Frame-by-Frame Rendering (Smooth 3D/Animation Guarantee)
Principle: Animation is driven by a virtual clock—virtual time advances by 1/30s only after each frame is rendered, completely decoupled from wall clock/render speed. Produces mathematically perfectly smooth frame sequences at any frame rate (30/60fps).
Page-side Contract (the captured page must implement, one-time modification):
const CAPTURE = location.search.includes("capture");
// ① Renderer enables preserveDrawingBuffer (screenshot fidelity)
// ② Expose step interface: advance dt virtual seconds → drive mixer/position/camera → render one frame
window.__ceremonyStep = (dt) => { /* mixer.update(dt); event table triggered by virtual time; render(); return virtualT; */ };
window.__ceremonyReady = () => actorsReady; // Asset load completion flag
// ③ Timeline changed from setTimeout to "virtual time event table": { t, fn } triggered by virtualT
// ④ Side effects without rAF loop (e.g., spotlight fade-in) set to final state directly in CAPTURE branch
Capture-side Script (CDP-driven):
await send("Page.navigate", { url: "<page>?capture=1" });
// Poll __ceremonyReady() === true
for (let i = 0; i < FPS * SECONDS; i++) {
await send("Runtime.evaluate", { expression: `window.__ceremonyStep(${(1/FPS).toFixed(6)})` });
const shot = await send("Page.captureScreenshot", { format: "jpeg", quality: 85 });
fs.writeFileSync(`f${String(i).padStart(4,"0")}.jpg`, Buffer.from(shot.data, "base64"));
}
Assembly: ffmpeg -framerate 30 -i f%04d.jpg -i music.wav -c:v libopenh264 -b:v 4000k -c:a aac -t <seconds> -movflags +faststart out.mp4
Discipline:
- All 3D/animated videos must use Route B—"should be smooth" is empty talk; offline rendering is the proof;
- Speed reference: about 0.5-0.8s per frame under SwiftShader (375 frames ≈ 4.5 minutes), be patient;
- DOM overlay elements (banners/popups) are captured in the same frame as canvas (Page.captureScreenshot includes DOM);
- Route B also applies to product 3D views (Floor3D/Stage3D need the same capture contract—just add the
?capturebranch in the page to reuse).
Full Four-Act Process (Route A · Real-Time Screen Recording)
Act 1 · Stack Up (Real Client, Not Browser)
# 1. Virtual display (necessary for headless environments)
nohup Xvfb :86 -screen 0 1600x1000x24 &
# 2. Backend + Frontend Preview (independent ports, avoid existing 8787/4173 instances)
SERVER_PORT=<PORT1> pnpm -C apps/server start &
WEB_PORT=<PORT2> SERVER_PORT=<PORT1> vite preview --port <PORT2> &
# 3. Electron Client (CDP mode, programmatically drivable)
DISPLAY=:86 \
WORKLOOM_SERVER_URL=http://localhost:<PORT1> \
WORKLOOM_MANAGE_SERVER=0 \
WORKLOOM_WEB_URL=http://localhost:<PORT2> \
./node_modules/.bin/electron --no-sandbox --in-process-gpu \
--remote-debugging-port=9333 \
--user-data-dir=/tmp/elec-rec \
apps/desktop/electron/main.cjs &
Discipline:
- Must use real Electron client (the product's actual form), never fake with browser tab screenshots;
- WebGL verification: Run
canvas.getContext('webgl2')via CDP—headless Chromium without WebGL triggers product degraded rendering (2D fallback), resulting in an "old version" video—a common failure point; - All processes are killed on sandbox sleep; check ports before starting:
fuser -k 9333/tcp <PORT1>/tcp <PORT2>/tcp.
Act 2 · Drive (CDP Simulates Real User)
Use CDP (http://127.0.0.1:9333/json → WebSocket) to orchestrate scripts:
| Operation | CDP Method |
|---|---|
| Navigate/Refresh state | Page.navigate + Runtime.evaluate (localStorage state control, e.g., clearing ceremonial markers like theater-ceremony-*) |
| Drag rotate view | Input.dispatchMouseEvent (mousePressed → segmented mouseMoved → mouseReleased, each step 40-50ms) |
| Scroll wheel zoom | Input.dispatchMouseEvent type=mouseWheel (deltaY ±240, interval 150ms) |
| Right-click pan | Same as drag rotate, button=right |
| Hover trigger | Move mouseMoved to position and pause (hover 0.5s triggers tooltip, stare 1.5s triggers nod) |
| Screenshot verification | Page.captureScreenshot (evidence at end of each act) |
Camera pacing (audience-friendly): Let the entry camera settle ≥8s before operating; leave 2-3s "breathing room" between actions; target total duration 60-100s.
Act 3 · Screen Recording
ffmpeg -y -f x11grab -video_size 1600x1000 -framerate 24 -i :86 \
-c:v libopenh264 -b:v 2500k -pix_fmt yuv420p out.mp4
- Codec discipline: This sandbox ffmpeg has no libx264; use libopenh264 (best compatibility) or libsvtav1;
- After recording, verify duration with
ffprobe; spot-check frames withselect=eq(n,...)tile collage; - Cut black leader:
ffmpeg -ss <N> -i in.mp4 -c:v libopenh264 -movflags +faststart out.mp4.
Act 4 · Dubbing (Two Routes)
Route A · Real-Time Capture (Preferred, Real Sound)
- Prerequisites: System has PulseAudio + Chinese TTS voice pack (speech-dispatcher + espeak-ng) and Chromium
speechSynthesis.getVoices().length > 0; ffmpeg -f pulse -i auto_null.monitorrecorded synchronously with video.
Route B · Post-Production Dubbing (Tested Route, Recommended)
Linux headless environment Chromium typically cannot get TTS voices (getVoices()=0), so use post-production:
- Neural voice sentence-by-sentence generation (edge-tts):
import edge_tts await edge_tts.Communicate(text, voice, rate="-5%", pitch="+0Hz").save(f"line{i}.mp3")- Verified usable Chinese voices:
zh-CN-XiaoxiaoNeural / XiaoyiNeural / YunjianNeural / YunxiNeural / YunxiaNeural / YunyangNeural(first run--list-voices—voices not in the list will definitely fail); - Rate limit strategy: 1.5s sleep between sentences + 5 retries with backoff on failure;
- Role voice mapping uses the product's VoiceEngine 7+1 presets (voice equals personality—keep a role consistent throughout the video).
- Verified usable Chinese voices:
- Programmatic sound effects (ffmpeg sine synthesis for fanfare/wind chimes);
- Timeline mixing + synthesis:
# Align each line with adelay to video timeline → amix audio mix → composite with video ffmpeg -i video.mp4 -i dub.aac -filter_complex "[1:a]apad[a]" \ -map 0:v -map "[a]" -c:v copy -c:a aac -b:a 160k \ -t <video duration> -movflags +faststart final.mp4- Major pitfall:
-shortestwill trim the video to the audio length—must useapadto pad silence + explicit-tduration; - Spot-check waveform: Use
astatsto check Peak/RMS (prevent silent tracks or clipping).
- Major pitfall:
Acceptance Checklist
- Video shows Electron client (not browser), WebGL 3D scene normal (not 2D fallback)
- Has real interaction traces (drag/zoom/pan/click), not static display
- Duration 60-100s, no black leader, faststart for streaming playback
- Audio version: voice intelligible, voice matches character, peaks not clipped, video not truncated by
-shortest - Spot-check at least 3 frames (beginning/middle/end)
Common Failure Points (Potholes Encountered)
| Pitfall | Solution |
|---|---|
| Headless Chromium no WebGL → captures 2D fallback video | Use real Electron (SwiftShader ready) |
| Electron binary missing (postinstall download failed) | Copy from node_modules/.pnpm/electron@*/dist in another repo on same machine |
| Single instance lock conflict / port in use | Use separate --user-data-dir + fuser -k to clear ports |
getVoices()=0 (Linux headless) | Use Route B post-production dubbing, don't fight it |
| edge-tts voice name not in list → NoAudioReceived | First --list-voices; differentiate roles by voice + pitch tweak |
Video truncated by -shortest | Use apad + explicit -t duration |
| All processes killed on sandbox sleep | Restack; check all four layers: Xvfb/server/preview/electron |