Skip to content

AI video skill for Claude Code & Codex — cinematic, editable product promos with Remotion: 124 shot recipe cards, 150 motion previews, beat sync, sound design, Motion Workbench & JianYing (CapCut CN) export.

feat(assets/lib): ClipCard — wrap external video clips as card heroes (review fixes) (#39)

SKY ZHAOec3cbd13e1d3
diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml
index c43bf4e..2e5df8b 100644
--- a/.github/workflows/pr-checks.yml
+++ b/.github/workflows/pr-checks.yml
@@ -11,6 +11,7 @@ on:
- 'references/shots/**'
- 'gallery/**'
- 'demos/**'
+ - 'assets/lib/**'
- '.github/workflows/pr-checks.yml'
permissions:
@@ -94,6 +95,16 @@ jobs:
# root at the repo top via a transient symlink
cd .. && ln -s template/node_modules node_modules
find demos -name '*.tsx' | sed 's|^|./|' > /tmp/demo-files.txt
+ # assets/lib components that only need remotion also get compiled.
+ # (three-dependent ones — FlatPanel, helpers/camera — are excluded
+ # because the template doesn't ship three.)
+ for f in assets/lib/ClipCard.tsx assets/lib/Caption.tsx \
+ assets/lib/DigitRoll.tsx assets/lib/FlashCut.tsx \
+ assets/lib/PageCam.tsx assets/lib/VerticalTicker.tsx \
+ assets/lib/helpers/motion.ts assets/lib/helpers/rand.ts \
+ assets/lib/helpers/shake.ts; do
+ echo "./$f" >> /tmp/demo-files.txt
+ done
echo "checking $(wc -l < /tmp/demo-files.txt | tr -d ' ') tsx files"
./node_modules/.bin/tsc --noEmit --strict --skipLibCheck \
--esModuleInterop --jsx react-jsx --target es2022 \
diff --git a/SKILL.md b/SKILL.md
index 8b27a9b..c3848a9 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -187,7 +187,9 @@ SFX;只有完整分镜确认后才进入最终素材采集。用户从 Gallery
## 资产使用方式
- `assets/lib/` 组件 **copy 进新项目**后自由修改(不 import 本库)。
- 清单:PageCam(2.5D 页面相机——一切"真实页面"镜头的地基)、DigitRoll、
+ 清单:PageCam(2.5D 页面相机——一切"真实页面"镜头的地基)、ClipCard(把外部
+ 视频素材 mp4 包成可被镜头卡运镜骨架驱动的"卡片主角",含 OffthreadVideo
+ 交叉淡化循环——素材短于镜头时无缝续播)、DigitRoll、
FlashCut、Caption、FlatPanel、VerticalTicker(3D 无限滚动墙)、
helpers(rand/shake/camera/motion)。FlatPanel 与 helpers/camera 需要
`three` + `@react-three/fiber` + `@remotion/three` 依赖,其余仅需 remotion。
diff --git a/assets/lib/ClipCard.tsx b/assets/lib/ClipCard.tsx
new file mode 100644
index 0000000..6827f5e
--- /dev/null
+++ b/assets/lib/ClipCard.tsx
@@ -0,0 +1,200 @@
+import React from 'react';
+import {
+ OffthreadVideo,
+ Sequence,
+ interpolate,
+ staticFile,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+// ClipCard — wraps an external video clip (mp4) into a "card hero" that shot
+// recipes designed for DOM/SVG subjects (spotlight-hero-card,
+// magician-card-flourish, neon-frame-orbit-drop, quad-split-parallel-scenes…)
+// can drive directly. Fills the library gap where every card assumes generated
+// DOM content or page screenshots, never real footage.
+//
+// Battle-tested in a delivered 39s promo (spotlight push-in at zoom 1.7 on a
+// 512×512 clip; 3-up quad-split with 32px captions after a Q11 readability
+// review finding — small cards need captionSize raised to keep ≥32px on-screen).
+//
+// Crossfade loop: OffthreadVideo (as of 4.0.484) has no `loop` prop and freezes
+// past media end. Pass `loopDurationInFrames` to enable a seamless dissolve
+// loop — each next pass fades in over the previous tail. The effective step is
+// `loopDurationInFrames - startFrom` (a `startFrom` trim shortens the playable
+// media), and layer count is derived from the enclosing shot's duration, not
+// the Composition's, so a short shot inside a long composition doesn't spawn
+// invisible layers. Layer audio is crossfaded with complementary `volume`
+// curves so an unmuted loop doesn't stack two full-volume tracks.
+
+const ACCENT = '#4da3ff';
+
+// Each loop layer crossfades BOTH its audio and its opacity at its edges:
+// an incoming fade 0→1 over `fadeIn` frames at the layer start, a steady body,
+// then an outgoing fade 1→0 over `fadeOut` frames ending at `step` — the frame
+// where the NEXT layer starts. Adjacent layers therefore overlap for exactly
+// `crossfade` frames and their envelopes are complementary (sum to 1), so an
+// unmuted loop never stacks two full-volume tracks; visual dissolve and audio
+// crossfade stay in sync since they share the same envelope.
+const LoopLayer: React.FC<{
+ src: string;
+ size: number;
+ muted: boolean;
+ startFrom: number;
+ fadeIn: number;
+ fadeOut: number;
+ step: number;
+}> = ({ src, size, muted, startFrom, fadeIn, fadeOut, step }) => {
+ const frame = useCurrentFrame();
+
+ // envelope(f): 0 at f=0 (unless fadeIn=0 → 1), 1 through the body, 0 at
+ // f=step+fadeOut. Adjacent layers are spaced `step` apart and each fades
+ // out over `fadeOut` into the next one's `fadeIn` window.
+ let envelope: number;
+ if (frame <= fadeIn) {
+ envelope = fadeIn === 0 ? 1 : interpolate(frame, [0, fadeIn], [0, 1], { extrapolateLeft: 'clamp', extrapolateRight: 'clamp' });
+ } else if (frame <= step) {
+ envelope = 1;
+ } else {
+ envelope = interpolate(frame, [step, step + fadeOut], [1, 0], { extrapolateLeft: 'clamp', extrapolateRight: 'clamp' });
+ }
+
+ const opacity = Math.max(0, Math.min(1, envelope));
+ const volume = muted ? 1 : opacity;
+
+ return (
+ <OffthreadVideo
+ src={staticFile(src)}
+ muted={muted}
+ volume={volume}
+ startFrom={startFrom}
+ style={{
+ position: 'absolute',
+ inset: 0,
+ width: size,
+ height: size,
+ objectFit: 'cover',
+ opacity,
+ }}
+ />
+ );
+};
+
+export const ClipCard: React.FC<{
+ src: string; // path under public/
+ caption?: string; // monospace caption bar under the clip
+ size?: number; // card edge (square clips)
+ radius?: number;
+ muted?: boolean;
+ captionSize?: number; // default 17 — raise on small/far cards to keep ≥32px on-screen text
+ startFrom?: number; // trim: play the clip from this frame
+ style?: React.CSSProperties;
+ loopDurationInFrames?: number; // playable clip length in comp frames → enables crossfade loop
+ loopCrossfadeInFrames?: number; // default 8
+ durationInFrames?: number; // enclosing shot duration — loop layer count is derived from this,
+ // not the Composition duration (a short shot in a long composition)
+}> = ({
+ src,
+ caption,
+ size = 560,
+ radius = 20,
+ muted = true,
+ startFrom = 0,
+ style,
+ captionSize = 17,
+ loopDurationInFrames,
+ loopCrossfadeInFrames = 8,
+ durationInFrames,
+}) => {
+ const { durationInFrames: compDuration } = useVideoConfig();
+ const capH = caption ? Math.round(captionSize * 2.6) : 0;
+
+ let video: React.ReactNode;
+ // Guard: a startFrom trim that reaches or exceeds the playable media (or any
+ // degenerate step) must NOT loop — falling back to a plain single pass keeps
+ // a visible, audible clip instead of a layer that instantly fades to 0.
+ // step must also be >= crossfade, else >2 layers overlap at once and the
+ // complementary envelopes no longer sum to 1 (visual/audio stack past full).
+ const step = loopDurationInFrames
+ ? loopDurationInFrames - startFrom - loopCrossfadeInFrames
+ : 0;
+ const canLoop =
+ !!loopDurationInFrames &&
+ loopDurationInFrames > loopCrossfadeInFrames &&
+ step >= loopCrossfadeInFrames;
+ if (canLoop) {
+ const shotFrames = durationInFrames ?? compDuration;
+ const n = Math.max(1, Math.ceil(shotFrames / step));
+ video = (
+ <div style={{ position: 'relative', width: size, height: size }}>
+ {Array.from({ length: n }, (_, i) => (
+ <Sequence
+ key={i}
+ from={i * step}
+ durationInFrames={loopDurationInFrames}
+ layout="none"
+ >
+ <LoopLayer
+ src={src}
+ size={size}
+ muted={muted}
+ startFrom={startFrom}
+ fadeIn={i === 0 ? 0 : loopCrossfadeInFrames}
+ fadeOut={loopCrossfadeInFrames}
+ step={step}
+ />
+ </Sequence>
+ ))}
+ </div>
+ );
+ } else {
+ video = (
+ <OffthreadVideo
+ src={staticFile(src)}
+ muted={muted}
+ startFrom={startFrom}
+ style={{
+ width: size,
+ height: size,
+ objectFit: 'cover',
+ display: 'block',
+ }}
+ />
+ );
+ }
+
+ return (
+ <div
+ style={{
+ width: size,
+ height: size + capH,
+ borderRadius: radius,
+ background: '#111116',
+ border: '1px solid rgba(255,255,255,0.10)',
+ boxShadow: '0 24px 80px rgba(0,0,0,0.55)',
+ overflow: 'hidden',
+ ...style,
+ }}
+ >
+ {video}
+ {caption ? (
+ <div
+ style={{
+ height: capH,
+ display: 'flex',
+ alignItems: 'center',
+ padding: '0 18px',
+ fontFamily: 'ui-monospace, Menlo, monospace',
+ fontSize: captionSize,
+ color: 'rgba(255,255,255,0.72)',
+ letterSpacing: 0.5,
+ borderTop: '1px solid rgba(255,255,255,0.10)',
+ }}
+ >
+ <span style={{ color: ACCENT, marginRight: 10 }}>▸</span>
+ {caption}
+ </div>
+ ) : null}
+ </div>
+ );
+};
diff --git a/demos/ui-entrance/clipcard-looping/ClipCardLooping.tsx b/demos/ui-entrance/clipcard-looping/ClipCardLooping.tsx
new file mode 100644
index 0000000..7784c84
--- /dev/null
+++ b/demos/ui-entrance/clipcard-looping/ClipCardLooping.tsx
@@ -0,0 +1,77 @@
+// clipcard-looping —— ClipCard 交叉淡化循环回归卡
+// 覆盖维护者 review 点名的三个边界场景:
+// 1) 未静音(muted=false)的交叉淡化循环——出层/入层音量互补淡入,不在重叠区
+// 叠加两条全量音轨;
+// 2) startFrom>0 与 loop 组合——有效循环步长 = loopDurationInFrames - startFrom,
+// 否则每层从 startFrom 起播、按全长步进,会在素材尾部冻结;
+// 3) 短 Sequence 嵌在长 Composition 里——层数按 shot 时长(durationInFrames prop)
+// 计算,而非 Composition 总时长,不会生成永远不会被看见的层。
+//
+// 素材:ClipCard 的 src 是 public/ 下的真实 mp4。渲染本 demo 前先把一段
+// 短视频放到项目的 public/clips/clipcard-demo.mp4(建议 30fps、方形)。
+// 三个场景共用同一段素材,但用不同参数驱动,方便对照回放。
+import React from 'react';
+import { AbsoluteFill, Sequence } from 'remotion';
+import { ClipCard } from '../../../assets/lib/ClipCard';
+
+export const CLIPCARD_LOOPING_DURATION = 120; // 4s @30fps
+const CLIP = 'clips/clipcard-demo.mp4';
+
+export const ClipCardLooping: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ background: '#0b0b0f',
+ display: 'flex',
+ flexDirection: 'column',
+ justifyContent: 'center',
+ alignItems: 'center',
+ gap: 36,
+ }}
+ >
+ {/* 场景 1:muted=false + loop —— 音量互补淡入,不出双音叠层 */}
+ <div style={{ display: 'flex', alignItems: 'center', gap: 24 }}>
+ <ClipCard
+ src={CLIP}
+ muted={false}
+ loopDurationInFrames={60}
+ loopCrossfadeInFrames={10}
+ durationInFrames={120}
+ size={200}
+ caption="muted=false · loop"
+ captionSize={11}
+ />
+ {/* 场景 2:startFrom=12 + loop —— 有效步长 60-12=48 */}
+ <ClipCard
+ src={CLIP}
+ muted
+ startFrom={12}
+ loopDurationInFrames={60}
+ loopCrossfadeInFrames={10}
+ durationInFrames={120}
+ size={200}
+ caption="startFrom=12 · loop"
+ captionSize={11}
+ />
+ </div>
+
+ {/* 场景 3:短 Sequence(120f)嵌进长 Composition(未传 durationInFrames,
+ 层数从 useVideoConfig 的 composition 时长算 → 需显式传 durationInFrames;
+ 这里用 Sequence 包一层模拟"短 shot 长工程"的结构) */}
+ <Sequence name="short-shot" from={0} durationInFrames={120} layout="none">
+ <div style={{ display: 'flex', alignItems: 'center', gap: 24 }}>
+ <ClipCard
+ src={CLIP}
+ muted
+ loopDurationInFrames={45}
+ loopCrossfadeInFrames={8}
+ durationInFrames={120}
+ size={200}
+ caption="45f clip · 120f shot"
+ captionSize={11}
+ />
+ </div>
+ </Sequence>
+ </AbsoluteFill>
+ );
+};