Communitygithub.com

yazzang-homelab/motion-studio

建構、除錯或加速 seek(t) 渲染引擎:渲染合約、canvas 與 page 捕捉、worker/子幀/區塊、確定性修復、Remotion 或 HyperFrames 交接。用於「渲染太慢」、「幀不一致」、「使用 Remotion」。

motion-studio 是什麼?

此技能專注於 Seek 引擎(課程步驟 07),這是一個時間軸驅動的渲染系統,將動畫視為程式而非影片。核心思想是:頁面為任意時間點 `t` 繪製精確幀,渲染器則依序走訪時間、捕捉每一幀並傳遞給 ffmpeg 編碼。由於不依賴時鐘,每次渲染結果都完全相同,修復只需一行程式碼修改後重新渲染。此為預設的 A 路線(Opus 選擇),除非使用者指名 Remotion 或 HyperFrames,此時應參照 `references/route-b.md`。 技能支援在 Claude Code、Cursor 或 Codex 等 AI 代理環境中使用,透過 Claude 技能目錄執行。它定義了詳細的渲染合約,包含頁面與驅動程式兩個部分:頁面負責繪製影格(`window.seek(t)`),驅動程式則管理 headless 瀏覽器、並行 worker 頁面、幀捕捉與 H.264 編碼。技能也提供多種捕捉模式(canvas 與 page)、效能調校選項(worker 數量、解析度縮放、子幀數、幀率)、確定性證明方法(透過 `__studio.hash` 與 `framesDigest`)以及故障排除指南。 此技能的主要優點在於其確定性:同一機器與瀏覽器建置下,幀像素完全一致。跨機器時字型渲染可能不同(DirectWrite、CoreText、FreeType),需以視覺比對。效能方面,在參考筆電上,12 秒的樣板影片三種格式的最終渲染約需 4 分鐘。技能也包含詳細的效能數據與瓶頸分析(捕捉為瓶頸),並支援可恢復的區塊渲染(`--chunk`),適合長時間或過夜渲染任務。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/yazzang-homelab/motion-studio/tree/HEAD/skills/seek-engine

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Seek 引擎(課程步驟 07)

此處的「影片」是程式,而非影片檔。頁面為任意時間點 t 繪製精確的幀;渲染器依序走訪時間,捕捉每一幀並傳送給 ffmpeg。輸出不依賴時鐘,因此每次執行渲染結果都相同,修復只需一行程式碼修改並重新渲染。這是路線 A,Opus 預設選擇的路線。除非使用者指名 Remotion 或 HyperFrames(此時請參閱 references/route-b.md)。

所有操作請在影片專案的根目錄(包含 studio.json 的資料夾)執行。若無,請先執行 /motion-studio:studio-init。此技能的檔案位於 ${CLAUDE_SKILL_DIR};下方相對連結指向該目錄(${CLAUDE_SKILL_DIR}/references/determinism.md、${CLAUDE_SKILL_DIR}/references/route-b.md)。

1. 兩個部分

部分檔案職責
頁面index.html、film/film.js、lib/runtime.js(+ lib/*.js)boot(film) 會載入 studio.json、audio/beats.json(可選)和已打包的字型,然後暴露 window.seek(t) 和 window.__studio
驅動程式tools/render.mjs(+ tools/studio.mjs)在 http://127.0.0.1:<random> 提供專案服務,啟動 headless 瀏覽器(Windows:Playwright 的 headless shell,絕非已安裝的 Chrome 或 Edge;macOS 和 Linux:Chrome、Edge,然後是內建的那個),開啟 N 個 worker 頁面,依序捕捉幀,編碼為一個 H.264 串流

頁面一律透過 http 提供服務。file:// 會破壞 fetch('studio.json')、ES 模組以及包含 # 或 % 的路徑。

2. 渲染合約

成員合約
?format=9x16&scale=1&render=1驅動程式發送的查詢;format 預設為 studio.primaryFormat,scale 範圍 0.1–1
window.seek(t, blur?)時間點 t 的同步繪製;循環影片以 loopT 包裝,其他影片限制在 [0, duration] 範圍內;回傳 true。可選的第二個引數 { frameT, sub, subs } 表示此次繪製是輸出幀(以 frameT 為中心)的第 sub 個子幀(共 subs 個);(頁面捕捉時對每次螢幕截圖都會發送此資訊)
__studio.readyPromise;在 config、節拍網格、字型(loadFonts 確認每個字型)和 setup() 完成後解析
__studio.error啟動失敗時的字串堆疊(驅動程式會列印它)
__studio.meta{ title, duration, fps, format, width, height, logicalWidth, logicalHeight, scale, bpm, loop, capture }
__studio.frame({ t, sub, shutter, fps, wrap })時間點 t 的 PNG 資料 URL;sub > 1 時會在頁面中累積居中的子幀(動態模糊);wrap: false 時即使是在循環影片中也繪製原始時間(限制在 [0, duration])
__studio.hash(t, { wrap, sub, shutter, fps })在 paint(t) 之後原始像素的 sha256(確定性檢查);也接受 hash({ t, wrap: false })。hash(0) 與 hash(duration, { wrap: false }) 是循環閉合不變量
__studio.pixels(t, w)小型 RGBA 縮圖,以 base64 表示(評論指標);在循環影片中總是進行包裝
__studio.cues() / shots() / gridSFX 提示、鏡頭區間、節拍網格,以 JSON 格式提供(由 sfx.mjs、stills.mjs --shots、critique.mjs 讀取)。shots() 按時間順序排列,僅列出場景,絕不包含 overlays;grid 帶有 hits
__studio.textUse() / coverage(family, weight, style, chars) / textTrack評論的字形檢查。若在載入前設定 window.__TEXT_TRACK__ = true(或使用 ?texttrack=1),lib/draw.js 會記錄 text()、kinetic() 和 textWidth() 為每個字型繪製的字元;textUse() 解析 [{ family, weight, style, chars }](針對目前為止已繪製的幀,請先對整個影片執行 seek()),coverage() 會對一個字型解析 { missing, checked }。預設為關閉,絕不會改變任何像素;text() 和 kinetic() 不會因未註冊的字型系列而拋出例外

在製作動態模糊幀時,場景在 c 中看到的內容:c.t 是目前正在繪製的時間(子幀時間,因此動態模糊會自行生效),c.frameT 是輸出幀的中心時間(對每個子幀都相同),c.frame 是輸出幀索引 floor(frameT x fps)(對每個子幀都相同),c.sub / c.subs 是子幀索引和總數。幀索引雜訊使用 c.frame(grain(g, W, H, c.frame) 在靜態影像、預覽和最終成品中看起來相同),「雙格」使用 stepTime(c.frameLt, 12)。詳細資訊:請參閱插件中的 docs/ARCHITECTURE.md 第 5.2 節。

影片程式碼必須遵守 references/determinism.md 中的規則。簡而言之:每個值都是 t 的函數;使用 rngFor(name, i) 為每個元素提供種子隨機性;禁止使用 Math.random、Date、performance.now、計時器、requestAnimationFrame、CSS 轉場或幀間狀態;字型和素材必須是本機檔案。npm run lint 會檢查這些規則,且插件鉤子會在每次編輯 film/、lib/ 和 index.html 時進行檢查。

3. 指令

目標指令
即時預覽(拖曳、空白鍵、方向鍵、[/] 鏡頭、F 格式、G 安全導引)npm run preview
環境檢查(Node、Playwright、瀏覽器、ffmpeg、字型、金鑰是否存在)npm run doctor
安裝 Windows 預設瀏覽器(Playwright 的 headless shell,約 115 MB)npx playwright install chromium-headless-shell(npm run setup:browser)
快速節奏檢查(半解析度、30 fps、無模糊)npm run animatic(寫入 out/animatic/<fmt>/silent.mp4)
渲染主要格式npm run render
渲染特定時間範圍以供檢查node tools/render.mjs --from 4 --to 6 --draft --out out/check(寫入 out/check/<fmt>/clip_4.00-6.00.mp4)
渲染所有格式npm run render:all
最終渲染,所有格式(會阻塞直到評論關卡通過;12 秒示範約需 4 分鐘,請在背景執行)npm run render:final
長片、可恢復的區段node tools/render.mjs --format all --final --chunk 10
每幀雜湊清單node tools/render.mjs --hash(寫入 frames.sha256;指定範圍則寫入 clip_<from>-<to>.sha256)

每種格式的輸出:out/<fmt>/silent.mp4、out/<fmt>/poster.png(在 studio.poster 或 0.35 x 持續時間處)和 out/<fmt>/render.json(fps、幀數、worker、瀏覽器版本、捕捉、編碼設定、秒數)。mix.mjs 會讀取 render.json 以取得確切的音訊長度。所有內容都在 out/<fmt>/.staging/ 中建構,並作為一個單元發布:先將舊檔案移到一旁,然後新檔案移入,silent.mp4 最後移入;任何失敗都會還原舊檔案。如果另一個程式持有了輸出檔(Windows 上的影片播放器、圖片檢視器),渲染會等待最多 30 秒(MOTION_PUBLISH_WAIT_MS),在開始時警告哪些檔案被開啟,否則會以 cannot replace <file>: EBUSY ... 停止,並將完成的渲染保留在 out/<fmt>/.staging/ 中(先前的輸出保持不變)。關閉該程式並從 .staging/ 複製檔案,或重新渲染。使用 --no-poster 的完整渲染會移除先前的 poster.png,不使用 --hash 的完整渲染則會移除先前的 frames.sha256,因此沒有輸出會描述較舊的剪輯。

僅當 --from/--to 遺漏了某些幀時,範圍渲染才是不完整的;它會寫入 clip_<from>-<to>.mp4 及其自己的 .json 和 .sha256,絕不取代 silent.mp4,且不能是 --final。覆蓋整個影片(或 --to 超過結尾)的範圍視為完整渲染。請將檢查用渲染放在 --out out/check 下,這樣 out/<fmt>/ 就只包含真正的影片。

4. 捕捉模式

模式設定方式如何製作一個幀用途
canvas(預設)無__studio.frame 在 t + ((j + 0.5) / sub - 0.5) * shutter / fps 處繪製 sub 個子幀,在頁面中累積像素,回傳一個 PNG所有繪製在 <canvas id="stage"> 上的內容
pagefactory 回傳 capture: 'page' 或 studio.json 中的 "capture": "page"seek(t) 然後對每個子幀執行 page.screenshot;ffmpeg tmix + select 混合每個群組DOM 影片(根據 t 更新的樣式元素)

shutter 0.5 是 180 度快門:模糊範圍跨越半個幀間隔。快速揮動和平移在 --sub 4 時可能會顯示重影複製;對於此類影片請提高到 --sub 8。頁面捕捉速度較慢(每個子幀一個螢幕截圖)並且繼承了 DOM 渲染差異,因此優先使用 canvas。

5. 效能調校

繪製次數 = 幀數 x 子幀數。一個 12 秒、60 fps、--sub 4 的影片,每種格式需要 2,880 次繪製。

旗標預設值效果使用時機
--workers Nmin(4, max(1, floor(cpus / 3)))一個瀏覽器中的並行頁面,將資料饋送給一個有序編碼器在大型機器上提高;如果 RAM 不足則降低
--scale s1canvas = even(round(W x s));0.5 = 四分之一像素草稿、長片的靜止畫
--sub Nstudio.subframes(4)每幀的子幀數草稿用 --sub 1;快速動作用 8
--fps Nstudio.fps(60)輸出幀率動畫用 30
--draft關encode.previewPreset + CRF 23任何非最終渲染
--crf N / --preset p16 / slowx264 品質 / 速度最終渲染時保留
--chunk S關可恢復的 out/<fmt>/.parts/seg_<a>_<b>.mp4,然後以 -c copy 拼接超過約 30 秒的影片、三種格式的最終渲染、過夜執行(中斷後可恢復而非重新開始)
--no-poster海報開啟跳過海報靜止畫批次檢查

在參考筆電(12 執行緒 i7-1255U、已安裝 Chrome、1080x1920、60 fps、4 個子幀、4 個 worker;Windows 預設現在是 headless shell,其每幀速度未重新測量,且在啟用即時防毒軟體的機器上每次工具執行會增加 15 到 25 秒的啟動時間)上測量:

設定每個輸出幀的時間15 秒 60 fps 的時間
課程的每個子幀螢幕截圖迴圈(僅捕捉,200 個弧線、文字和漸層的合成場景)約 1,575 毫秒約 24 分鐘
使用 4 個頁面的頁面內累積(相同的合成場景,僅捕捉,像素相同)約 148 毫秒約 2.2 分鐘
此渲染器在範本的 12 秒示範影片上從頭到尾執行,最終 x264 編碼9x16 為 123 毫秒,1x1 為 75 毫秒,16x9 為 118 毫秒9x16 為 1.8 分鐘(12 秒影片的三種格式約 4 分鐘)

前兩行是決定設計的僅捕捉基準測試;最後一行是真實影片的成本,並且是報價時應引用的數字(它會隨著場景複雜度和其他程式對機器的負載而增加,三種格式最多約 5 分鐘)。x264 -preset slow 在該尺寸下編碼約 18 fps,因此捕捉是瓶頸。進度、fps 和 ETA 會每隔一秒鐘輸出到 stderr。請在背景啟動最終渲染並輪詢日誌;切勿在前景等待它。

6. 證明確定性

  1. npm run critique 執行確定性檢查:在跨越每個鏡頭邊界和提示的時間點(加減一個幀)進行 __studio.hash,傳遞 A 按順序,傳遞 B 隨機順序,傳遞 C 在重新載入後。out/review/<fmt>/metrics.json 列出每個不匹配的 t。
  2. 在範圍渲染後,透過對相同範圍進行兩次雜湊渲染來證明該範圍是確定性的。改變 worker 數量以便也涵蓋並行性: node tools/render.mjs --from 0 --to 2 --hash --draft --no-poster --json --workers 1 --out out/check/a 和 node tools/render.mjs --from 0 --to 2 --hash --draft --no-poster --json --workers 4 --out out/check/b。 範圍渲染絕不會觸及 silent.mp4。每次執行會寫入 out/check/<a|b>/<fmt>/clip_0.00-2.00.mp4 加上 .json 和 .sha256(每幀一行:index t sha256),其 --json 行會報告 framesDigest,即由換行符號連接的雜湊列的 sha256。每種格式中相等的 framesDigest 值表示幀相同。如果不同,請比較兩個 .sha256 檔案:git diff --no-index --quiet out/check/a/<fmt>/clip_0.00-2.00.sha256 out/check/b/<fmt>/clip_0.00-2.00.sha256 在匹配時退出碼為 0,而 git diff --no-index 會顯示第一個不同的幀。切勿使用 md5,它在 Windows 或 Linux 上不存在。
  3. 不要對 mp4 進行雜湊:x264 輸出會隨執行緒數量而變化,因此 mp4 雜湊在不同機器上會不同。framesDigest 涵蓋了輸入編碼器的幀 PNG,這正是確定性所要確保的。

承諾是在同一機器和瀏覽器建置下(記錄在 render.json 中)獲得位元組相同的幀。跨機器時,字型渲染方式不同(DirectWrite、CoreText、FreeType);請以視覺方式比較。

7. 疑難排解

症狀原因修正
Executable doesn't exist ... chromium_headless_shell,或 could not launch a browser: no safe browser found.(Windows)未下載 Playwright 的 headless shell(npm install 不會下載它)npx playwright install chromium-headless-shell。在 macOS 和 Linux 上,已安裝的 Chrome 或 Edge 也可用;在 Windows 上,已安裝的瀏覽器是受保護的選擇加入選項(studio.json 中的 "browser": "chrome"、MOTION_BROWSER=chrome),因為每次使用全新設定檔啟動都會被計為一次失敗的 Windows 登入
Windows 帳戶被鎖定、來自 chrome.exe 的安全性事件 4625,或 refusing to start chrome: N launches ...使用全新設定檔啟動了已安裝的 Chrome 或 Edge(空白密碼測試 = 登入失敗)如上所述切換到 headless shell,並取消設定 MOTION_BROWSER / MOTION_CHROME_PATH;確認指令和原因請參閱 ${CLAUDE_SKILL_DIR}/../studio-init/references/troubleshooting.md 中的「Windows account gets locked out while rendering or testing」
ffmpeg not found不在 PATH 中,ffmpeg-static 缺失npm i -D ffmpeg-static 或設定 FFMPEG_PATH;npm run doctor 會列印每個作業系統的指令
在 Windows 上自己的腳本中出現 spawn EINVAL在沒有 shell 的情況下衍生 npm/npx .cmd 包裝程式使用 spawn('npm.cmd', args, { shell: true });工具已經這麼做了
font missing: 700 64px "X" 或準備逾時字型系列未打包或拼寫錯誤npm run fonts -- add "X:400,700";使用 studio.json brand.fonts 中的名稱
空白或部分幀,日誌中的頁面錯誤場景繪製中的例外驅動程式會列印 __studio.error 和控制台錯誤;在該時間點使用 npm run preview 重現

[此處可能還有更多關於 __studio.error 與 console.error 的說明]

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

yazzang-homelab/motion-studio

Make Claude watch its own frames: critique.mjs evidence, harsh 7-axis scores, timestamped P0/P1/P2 problems in docs/review_log.md, fix the 3 worst, re-check, pass the gate. Use for 'critique it', 'review the frames', 'is it good'.

yazzang-homelab/motion-studio

Plan long-form or overnight films: director's brief (PLAN FIRST or GO, budget, definition of done), ANIMATION_GUIDE + STORYBOARD, chapter subagents, gates, chunked render. Use for 'overnight film', 'music video', '2-minute film'.

yazzang-homelab/motion-studio

Make a launch video, app or product reel, explainer or motion ad from code, end to end: brand assets from a URL, beat-grid shot list, synced sound, critique loop, all formats. Default for new video requests; not footage edits.

yazzang-homelab/motion-studio

Brand-asset stage of a product film (motion-reel runs the whole film): capture real screenshots, logo, colors and fonts from a URL, never redraw UI; brand story beats; voice + mascot. Use to grab or fix a brand's assets.

yazzang-homelab/motion-studio

Turn a reference (a frame, a video or an image library) into docs/style_guide.md and a beat-grid shot list: measure cuts, palette and pace, take grammar not content, wait for OK. Use when the user supplies or names a look.

yazzang-homelab/motion-studio

Ship every format from one timeline, then package it: layout() reframing (never crop), render all formats, per-format checks, deliver.mjs, a brand skill, a service offer. Use for 'export 9:16 and 16:9', 'deliver', 'make a skill'.

yazzang-homelab/motion-studio

The viral one-line 'showreel for a résumé' prompt: why it works (anatomy), the credited quote, and seeded variants that avoid look-alike reels; runs it as an engine test. Use for that prompt, its variations, or a showreel.

yazzang-homelab/motion-studio

Score a film to its beat grid: measure a track (beats.mjs) or synthesize one (score.mjs), cue SFX from the film, add voice, mix to -14 LUFS / -1 dBTP at exact length. Use for 'add music', 'sync to the beat', 'SFX', 'loudness'.

yazzang-homelab/motion-studio

Make motion feel physical with closed-form springs from lib/motion.js: presets, springFromFeel, track() for multi-target values, loopTrack loops, indicators, text swaps. Use for 'feels linear', 'add bounce', 'easing to springs'.

yazzang-homelab/motion-studio

Scaffold a motion-studio film project (seek(t) renderer, springs, beat grid, synthesized sound, critique tools), install it, set up the browser, run doctor. Use for 'set up the motion studio', 'new film project', 'init studio'.

yazzang-homelab/motion-studio

Write a six-part XML state spec for a one-shape UI morph film (inputs, direction, structure, build, gotchas, start): states on downbeats, cursor-driven changes, seamless loop, approval gate. Use for 'UI morph', 'state list'.

相關技能