Communitygithub.com

remotion-video-texture

把真实录屏/视频当纹理贴到 three.js 的屏幕、手机、显示器或卡片上,做设备 mockup(笔记本里跑着真软件、手机里放着真视频)。当需要"屏幕里是真实画面、镜头和光效是动效"、或者遇到 @remotion/media 的 Video 放进 ThreeCanvas 后导出全黑、屏幕闪黑帧、预览正常导出空白时使用。

remotion-video-texture 是什么?

remotion-video-texture is a Claude Code agent skill that 把真实录屏/视频当纹理贴到 three.js 的屏幕、手机、显示器或卡片上,做设备 mockup(笔记本里跑着真软件、手机里放着真视频)。当需要"屏幕里是真实画面、镜头和光效是动效"、或者遇到 @remotion/media 的 Video 放进 ThreeCanvas 后导出全黑、屏幕闪黑帧、预览正常导出空白时使用。.

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

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

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.

相关技能