Communitygithub.com

remotion-video-texture

Map real screen recordings/videos as textures onto three.js screens, phones, monitors, or cards for device mockups (e.g., a laptop running real software, a phone playing an actual video). Use this when you need "real footage inside the screen, dynamic camera and lighting effects outside," or when placing a @remotion/media Video inside ThreeCanvas results in all-black exports, screen flickering with black frames, or blank output despite a normal Studio preview.

What is remotion-video-texture?

This skill enables Remotion users to map real screen recordings or videos as textures onto 3D objects in three.js, such as laptop screens, phone displays, or monitor panels, creating realistic device mockups. It is essential when the scene requires authentic footage inside the screen while keeping the surrounding camera motion, lighting, and effects frame-driven. The approach uses a `<Video>` component with `onVideoFrame` placed outside `<ThreeCanvas>`, a 2D canvas that draws video frames, and a `THREE.CanvasTexture` that updates per frame. Key pitfalls include the player being inside the ThreeCanvas (causing `onVideoFrame` to never fire during export), canvas size re-initialization that clears the surface, and the need to synchronously call `renderer.advance()` during rendering to avoid capturing stale frames. The skill provides two React assets (`useScreenVideoTexture.tsx` and `useScreenDecks.tsx`) that handle texture creation, frame drawing, preloading the first frame, and variable playback speed, with detailed configuration for anisotropy, color space, and tone mapping to ensure visual fidelity.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/GhostFace-yz/remotion-skill-store/tree/HEAD/skills/remotion-video-texture

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Video as Texture: Mapping Screen Recordings into a 3D Device Body

Positioning: The Screen Recording is Footage, Not Animation

This distinction must be clear (see decision in remotion-frame-driven-refactor/references/recording-vs-frames.md):

  • Content inside the screen: Real screen recording, captured once, serves as footage.
  • Everything outside the screen: Device motion, camera zooms, lighting, transitions, text — all frame-driven.

Example: In a vertical promo video, a laptop rises from the bottom, the camera zooms in, and finally the whole device fades out with a dot-matrix dissolve — all computed from frame; only the 3491 frames of VS Code operations inside the screen are real footage (2218×1440 / 30fps / ≈143 MB).

Architecture

<Video headless muted onVideoFrame>   ← Must be placed outside <ThreeCanvas>
        │  videoFrame
        ▼
<canvas 2d>  ──drawImage──►  THREE.CanvasTexture  ──►  screen material
        ▲
        └── needsUpdate per frame + renderer.advance()

Three Must-Hit Pitfalls

1. The Player Must Be Placed Outside <ThreeCanvas>

If placed inside r3f's Canvas subtree, during export onVideoFrame never fires — the screen remains black; Studio preview may appear normal, leading you to believe everything is fine. Use <Sequence layout="none"> at the layout level to avoid inserting extra DOM nodes.

2. Canvas Size Must Only Be Initialized Once

if (surface.canvas.width < 16) {   // Only set once
  surface.canvas.width = width;
  surface.canvas.height = height;
}

Assigning to canvas.width clears the contents. If drawImage fails on any frame due to timing issues (e.g., a closed VideoFrame), the canvas becomes completely black — the symptom is "the screen flickers between black and normal frames."

3. Synchronous Redraw During Export

if (isRendering) {
  rendererRef.current?.advance();     // Don't wait for the next frame; the snapshot arrives immediately
} else {
  rendererRef.current?.invalidate();  // Studio preview
}

Call advance() immediately after drawImage, otherwise the snapshot will capture the previous frame's content.

The argument to advance() is "clock time" – do not pass performance.now() — rendering the same frame twice will yield different values, and the scene will no longer be f(frame). Convert using the frame number: advance((frame / fps) * 1000) (already implemented in assets/useScreenVideoTexture.tsx). Likewise, if there is any useFrame((state, delta) => ...) reading delta, change it to use useCurrentFrame().

Complete Scaffold

See assets/useScreenVideoTexture.tsx (texture + per-frame drawing) and assets/useScreenDecks.tsx (two player segments: preload first frame + variable-speed playback). Mounting method:

const { texture, onVideoFrame, rendererRef } = useScreenVideoTexture();

<ThreeCanvas frameloop="never" ...>
  <RendererBridge rendererRef={rendererRef} />
  <mesh>
    <planeGeometry args={[16, 10]} />
    <meshBasicMaterial map={texture} toneMapped={false} />
  </mesh>
</ThreeCanvas>

{/* Player outside the canvas */}
<ScreenDecks
  src={staticFile("screen/screen.mp4")}
  startFrame={430}          // Which composition frame to start playing
  playbackRate={1.5}        // Must match the variable speed of the timeline
  onVideoFrame={onVideoFrame}
/>

Detailed Checklist

ItemApproach
Preload first frameBefore playback, freeze a segment with <Freeze frame={0}> so the screen already has an image during the rising phase
Variable speedUse the same constant for playbackRate and the composition's time remapping, otherwise audio/video and subtitles will desync
Freeze at the endIf the video is shorter than the composition: let the player run until the composition ends; the player clamps to the last frame; do not use <Freeze> to freeze
Tilt blurtexture.anisotropy = gl.capabilities.getMaxAnisotropy(); use mipmap for minFilter, Linear for magFilter
Colorstexture.colorSpace = THREE.SRGBColorSpace, material toneMapped={false}, renderer NoToneMapping
FlickeringFirst check the three pitfalls above; if still flickering, use chunked rendering (see remotion-chunked-export)
Footage sizeThe 143 MB screen recording in the example overwhelmed concurrent decoding (40% black frames). Compress if possible, or use chunked export as a safety net (see remotion-chunked-export)

When NOT to Use This Approach

  • The screen content is actually a web page / chart / code: Render it frame-driven with the DOM — don't screen-record; it will be blurry and non-editable.
  • You just want to "place a video in the frame as a picture-in-picture": Use <Video> or <OffthreadVideo> directly; no 3D is needed.
  • You need interactive fake UI inside the screen: Rendering with React and then mapping it as a texture is feasible, but do not screen-record.

Accompanying Assets

FilePurpose
assets/useScreenVideoTexture.tsxcanvas → CanvasTexture, includes size initialization only once, failsafe to keep the previous frame
assets/useScreenDecks.tsxPreload first frame + variable-speed playback (two player segments)

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

Related Skills