framefields README

项目的 README,来自 github.com/gatewai-dev/framefields。合并为一个 markdown 文件:README.md。

framefields — code-first video, rendered natively on WebGPU

Compositing, motion graphics, and 3D for code-first video — one npm package that AI agents drive with code.

Documentation  ·  Website  ·  Models  ·  Discord  ·  Examples

npm docs license status discord youtube node engine gpu

Add to your agent

Teach Claude Code, Cursor, Codex, Copilot, Hermes, and 70+ others how to author, animate, and render compositions:

npx skills add gatewai-dev/framefields

Or use the desktop app

framefields, the desktop app for macOS and Linux: make videos by talking to an agent. It writes the code, plays the film and renders on your GPU.


Framefields is built for coding agents. It packs the capabilities usually split across three desktop creative suites—Photoshop-style compositing & VFX, After Effects-style typography & motion graphics, and Blender-style 3D scenes & cameras—into a single lightweight npm package.

Made with framefields

Every frame is rendered by framefields directly from TypeScript in examples/. Click a still to watch on YouTube:

Fable 5.2 & Framefields - What is Hawking Radiation ?
Fable 5.2 & Framefields - What is Hawking Radiation ?
41_hawking_radiation
News explainer film about the Palm Beach County jet crash
News explainer
33_news_explainer
Relay product film
Relay
32_relay
Shard storm vision dancer showcase film
Shard storm
31_shard_storm
Physics dancer showcase film
Physics dancer
28_physics_dancer
Mac keyboard from 3D primitives
Mac Keyboard
26_mac_keyboard_from_3d_primitives
Framefields launch film
Framefields launch
22_framefields_launch
Full Circle film
Full Circle
21_full_circle
Dancer showcase film
Dancer showcase
19_framefields_film

Installation

pnpm add framefields

Starting a new film? framefields init sets up the whole project: package.json, TypeScript, a film.ts to edit and a render.ts to render it, assets/ with Git LFS, and the Inter, JetBrains Mono, and Noto Color Emoji fonts:

pnpm dlx framefields init my-film --install   # or: npx framefields init my-film --install
cd my-film && pnpm frames -- 0 30 60          # first frames in output/

Run it inside an existing project to add framefields there; it only fills in what's missing and never overwrites your files. It asks nothing, so it works in CI and on remote servers too.

Requirements: Node.js ≥ 22. Native GPU acceleration via WebGPU / Dawn (macOS Metal, Linux Vulkan, Windows D3D12). Machines without a dedicated GPU can render on the CPU via Mesa lavapipe on Linux or WARP on Windows (~10–12× slower than GPU; suitable for headless CI and test frames).


Quickstart

import { Composition, Layer, LayerAnimation } from "framefields";

// 1. Create a 1080p60 composition
const comp = new Composition({
  width: 1920,
  height: 1080,
  fps: 60,
  durationFrames: 180, // 3 seconds
  backgroundColor: "#090a0f",
  fonts: ["assets/fonts/Inter.ttf", "assets/fonts/SpaceGrotesk.ttf"],
});

// 2. Physical snap-overshoot entrance animation
const entrance = LayerAnimation.create()
  .fadeIn(0, 20, "power2.out")
  .fromTo("y", 60, 0, { start: 0, end: 35, ease: "back.out(1.5)" })
  .fromTo("scale", 0.92, 1.0, { start: 0, end: 35, ease: "back.out(1.2)" });

// 3. Assemble a responsive flex-layout card with Slug vector type
const heroCard = Layer.box({
  width: 760,
  height: 380,
  background: "#141721",
  borderRadius: 24,
  borderColor: "#262b3d",
  borderWidth: 1.5,
  padding: 40,
  children: [
    Layer.flex({
      dir: "column",
      gap: 16,
      children: [
        Layer.text("FRAMEFIELDS ENGINE", {
          fontSize: 16,
          fontWeight: 700,
          fill: "#6366f1",
          letterSpacing: 2.0,
        }),
        Layer.text("Code-First Video", {
          fontSize: 48,
          fontWeight: 700,
          fill: "#f8fafc",
          fontFamily: "SpaceGrotesk",
        }),
        Layer.text("Direct GPU rendering without headless browser overhead.", {
          fontSize: 20,
          fill: "#94a3b8",
          lineHeight: 28,
        }),
      ],
    }),
  ],
}).animate(entrance);

comp.add(heroCard);

// 4. Render to hardware-encoded MP4
const { filePath } = await comp.renderVideo({
  outputPath: "output/hero.mp4",
  quality: "high",
});

console.log(`Rendered to: ${filePath}`);
process.exit(0);

Components

Ready-made motion pieces you own: a mouse pointer with clicks and drags, a camera that zooms to them, window and device frames, word-timed captions, text reveals, counters, terminals, code blocks, title cards, lower thirds, logo reveals, backdrops, audio waveforms and more. Like a shadcn registry, framefields add copies a component's source into your project instead of hiding it in the package, so you can change any curve, glyph or layout.

npx framefields list                           # every component, one line each
npx framefields add mouse-pointer focus-zoom   # writes src/components/<name>/
import { MousePointer } from "./components/mouse-pointer/index.js";

const pointer = MousePointer({
  path: [{ to: [400, 300] }, { to: [960, 540], click: true }],
});
comp.add(pointer);

// Every event is a cue: key a button press or a click sound to it.
const clickAt = pointer.cues.clicks[0].frame;

Installed components import only framefields and the shared toolkit in framefields/components, and bring along any component they build on. Files you've edited are never overwritten unless you pass --overwrite.


Select and track a subject

Select a specific object with a point or box (SAM 2.1 Tiny or Small), or by description, several at once, or a whole group as one mask (SAM 3), and track it through video. Masks, bounds, motion and optional matched pose feed the existing vision signals; the same clip masks drive cutouts. The SAM code ships in framefields and loads only when a clip uses it; model weights download on first use, and SAM 3's are under Meta's SAM License, which you accept explicitly (see NOTICE.md).

const subject = Layer.video("assets/source.mp4", {
  width: 1920, height: 1080, fit: "contain",
}).withVision({ mode: "matte" });
comp.add(subject);
const tracked = comp.vision(subject, {
  sam2: { prompts: [{ frame: 0, points: [{ x: 0.5, y: 0.5, label: 1 }] }] },
});
const target = tracked.signals.objects.get(1);

// SAM 3 (Meta SAM License, accepted explicitly): every student in the shot as one mask, from one prompt
comp.vision(subject, {
  acceptSamLicense: true,
  sam3: { text: "students in black jackets", merge: true },
});

Prompts use normalized source coordinates. Model files download lazily, inference runs locally, and cached source-frame results support seeking and time remapping. See the vision guide for choosing a model, corrections, several objects, backends, costs and mask alignment limits.


AI Gateway

Framefields provides built-in access to the AI Gateway, allowing agents and developers to generate cinematic video, images, music, and voiceovers directly from code using hundreds of hosted models. Explore the full model catalog in the AI Gateway or read the integration guide in the documentation.

The gateway is optional. To use it, create a key at framefields.dev/dashboard and set FRAMEFIELDS_API_KEY. In a project made with framefields init, copy .env.example to .env and put the key there; render.ts loads it.


Documentation

Everything else—including full API references, interactive tutorials, and guides—is available at framefields.dev/docs:


Community & License

Licensed under Apache-2.0.

framefields (gatewai-dev/framefields)

正在搜索数据库…

这是什么?Framefields 是一个“代码优先”视频的 TypeScript npm 包:你用代码写好合成(图层、3D、文字排版、音频、图表),它通过 WebGPU/Dawn 在 GPU 上原生渲染成 MP4,不需要桌面创意套件。
这是桌面应用还是代码库?它是一个 npm 库,不是图形界面应用。它把人们通常分散在 Photoshop 式合成、After Effects 式动效/排版和 Blender 式 3D 里的东西打包成一个完全由 TypeScript 代码驱动的包。
怎么用它渲染出视频?你编写一个 TypeScript 合成(图层、摄像机、文本、音频、图表),检查它的帧,然后调用渲染管线生成 MP4。如果你在用编程智能体,也可以一行命令安装 framefields Agent Skills。
我需要无头浏览器或特殊的 GPU 配置吗?不涉及无头浏览器或 Puppeteer/Chromium。它直接通过 Dawn/WebGPU 渲染,以 Metal 或 Vulkan 作为原生后端,可运行在 Node.js 或支持 WebGPU 的现代浏览器中。
它现在稳定到可以放心依赖吗?它明确处于 beta 阶段:API 可能随版本变化,一些功能可能仍不完整或不稳定。
它究竟是为谁打造的?它主要面向 AI 编程智能体——Claude Code、Codex、Cursor、Hermes、Gemini CLI、Copilot 等——以编程方式驱动,同时也面向用代码做动态图形、而不是手工桌面编辑的开发者。
它需要真实 GPU 才能运行吗?需要,它直接在 GPU 硬件上渲染(Dawn/WebGPU/Metal/Vulkan),而不是软件光栅化,并设计为运行在带 GPU 的云端工作节点上(AWS G4/G5、Modal、RunPod、Kubernetes),每个工作节点大约占用 200–400 MB 内存。
内置的视觉/追踪功能是怎么工作的?配套包(@framefields/vision)通过 onnxruntime 运行 ONNX 模型(RTMDet-Ins、RTMO、MediaPipe Selfie Segmenter),执行目标检测、实例分割、姿态估计和人像抠图,把结果输入可驱动动画的响应式信号。
它能制作动画图表吗?可以,Layer.chart 用 d3 处理比例尺和几何,构建折线、面积、柱状、散点、K 线、饼图和环形图,渲染成普通节点,能像其他图层一样做动画并置于 3D 空间。
为什么要避开 Puppeteer 这类无头浏览器?Puppeteer/Chromium 管线会增加进程开销、不确定的 DOM 重排和缓慢的截图采集。Framefields 直接与 GPU 通信并用硬件编码视频,每个工作节点大约用 200–400 MB 内存,而 Chromium 要 2–4 GB。
它能加载哪些 3D 模型格式?它内置 OBJ、FBX、glTF/GLB、STL、PLY、VOX、3DS 和 OFF 的零依赖解析器,这些模型可以放进统一的 3D 场景图,支持 PBR 着色和阴影。
大小
21.9 MB
星标
535
更新
提交Nov 18
时长
2个月
提交 · 90 天