Manim Motion Studio
使用 Manim Community、ffmpeg 和模組化 Python 媒體套件,建立清晰流暢的 60fps 程序化動畫、執行 AI 輔助影片編輯管線,並將影片製作與 Notion 同步。
模組化安裝 (scripts/setup_manim.sh)
僅安裝您需要的設定檔,以避免不相容的 GUI、CV 或 3D 相依性衝突:
bash scripts/setup_manim.sh core # manim + imageio-ffmpeg + pillow + numpy + scipy
bash scripts/setup_manim.sh editing # + av, moviepy, scenedetect, opencv-headless, faster-whisper, pydub
bash scripts/setup_manim.sh plugins # + manim-slides, manim-physics, manim-voiceover
bash scripts/setup_manim.sh vision # + opencv-python-headless, mediapipe, scikit-image
bash scripts/setup_manim.sh audio # + librosa, pydub, soundfile, faster-whisper
bash scripts/setup_manim.sh notion # + notion-client
bash scripts/setup_manim.sh full # 完整無衝突堆疊 (Manim + AI 編輯 + 外掛 + Notion)
如果系統缺少 ffmpeg,scripts/setup_manim.sh 會將 imageio_ffmpeg 的內建二進位檔建立符號連結到 /tmp/bin/ffmpeg,而 scripts/render.py 和 scripts/video_edit.py 都會自動將其加入 PATH。
無 LaTeX 可攜性規則: 最小化
pip install manim環境不包含pdflatex。請務必在標籤中使用Text/MarkupText,並在Axes、BarChart和ThreeDAxes中傳遞label_constructor=Text(在axis_config={"label_constructor": Text}內),除非您已確認安裝了latex和dvisvgm以使用MathTex/Tex。
工作流程
- 從 Notion 提取摘要、腳本或資料(透過已連接的 Notion 應用程式或
scripts/notion_sync.py),當您從工作區的分鏡腳本或 KPI 表格開始工作時。 - 從下方能力矩陣選擇正確的 Scene 類別與套件(快速堆疊請參考
references/python-motion-ecosystem.md,完整 18 節目錄請參考references/python-animation-library-catalogue.md)。 - 從
templates/中的驗證模板開始,或結合references/中的模式。 - 以草稿品質快速預覽(
--quality draft),在進行完整 60fps 渲染前確認時間軸、佈局、相機追蹤及構圖。 - 使用
scripts/render.py以目標長寬比渲染(切勿同時使用-qh與自訂-r尺寸)。 - 使用
scripts/video_edit.py進行編輯、字幕、重構、混音與匯出(combine,detect-scenes,auto-captions,burn-subtitles,smart-reframe,beat-markers,duck-audio,mux-audio,overlay,trim,speed,gif,probe)。 - 透過
ffmpeg視覺檢查萃取影格,然後交付最終的.mp4或.gif,並將渲染記錄回 Notion。
能力矩陣
| 領域 | 核心類別、動畫與工具 | 參考 / 模板 |
|---|---|---|
| 動態圖形與相機 | MovingCameraScene, ZoomedScene, self.camera.frame, LaggedStart, MarkupText, rate_functions, 分層發光描邊 | references/motion-graphics-camera.mdtemplates/motion_graphics_camera.py |
| 描邊繪製與變形 | Create, DrawBorderThenFill, Write, ShowPassingFlash, VMobject 貝茲路徑, SVGMobject, TransformMatchingShapes, Homotopy | references/stroke-drawing-morphing.mdtemplates/stroke_drawing_morphing.py |
| UI 載入器、微互動與展示影片 | 20 種 UI 載入器(彈跳球、液體填充、骨架/文字微光、軌道、輪幅/漸層轉圈、追逐方塊、電池),macOS 瀏覽器 chrome,漸進式檢查清單,5×4 同時 Bento 網格 | references/loaders-and-ui-microinteractions.mdtemplates/loaders_and_microinteractions.py |
| 關節角色與自訂背景 | 2 關節 FK/IK 角色骨架、擠壓與拉伸、眨眼/表情、多幕 ValueTracker 時間軸、dt 安全的相機追蹤、ImageMobject 紙張/桌面場景、背景人物去除 | references/character-rigging-and-backgrounds.mdtemplates/character_rig_scene.py |
| 3D 場景與曲面 | ThreeDScene, ThreeDAxes, Surface, move_camera, begin_ambient_camera_rotation, add_fixed_in_frame_mobjects | references/3d-charts-physics-hybrid.mdtemplates/three_d_showcase.py |
| 資料視覺化與圖表 | Axes, BarChart, NumberPlane, AnnularSector, get_riemann_rectangles, ValueTracker + always_redraw 即時計數器 | references/3d-charts-physics-hybrid.mdtemplates/data_viz_dashboard.py |
| 程式碼、數學、物理與圖論 | Code, Table, Brace, SurroundingRectangle, apply_matrix, ComplexPlane, ArrowVectorField, StreamLines, Graph/DiGraph, add_updater(mob, dt) | references/3d-charts-physics-hybrid.mdtemplates/math_code_and_diagrams.py |
| 混合照片 / CV 影片 | ImageMobject + OpenCV (cv2.inpaint, cv2.remap float32) + MediaPipe FaceLandmarker/HandLandmarker | references/3d-charts-physics-hybrid.md |
| 更廣泛的 Python 動畫生態系 | manim-slides, manim-physics, manim-voiceover, av, moviepy, lottie, cairosvg, pytweening, pymunk, transitions, bpy/pyvista, 相容性矩陣 | references/python-motion-ecosystem.md |
| 完整動畫函式庫目錄 | 18 節目錄:數學/解說、2D/遊戲、創意程式設計、向量/SVG、影片編輯、CV/AI、3D、物理、圖表、GUI、說故事、緩動、音訊、輔助工具、pip 索引、警告、目標組合、核心堆疊 | references/python-animation-library-catalogue.md |
| 影片編輯與 AI 後期製作 | scripts/video_edit.py, detect-scenes (PySceneDetect), auto-captions (faster-whisper), burn-subtitles, smart-reframe (OpenCV 追蹤), beat-markers (librosa), duck-audio, xfade 合併, 混合長寬比模糊填充, 透明 .mov 疊層, GIF | references/video-editing-postprod.mdscripts/video_edit.py |
| Notion 製作工作流程 | 已連接的 Notion 應用程式 + scripts/notion_sync.py:搜尋、讀取摘要/分鏡腳本、將資料庫指標匯出為 JSON 以用於 Manim 圖表、建立分鏡腳本頁面、更新狀態、記錄渲染的 MP4 中繼資料、附加區塊與留言 | references/notion-video-workflows.mdscripts/notion_sync.py |
基本渲染、影片編輯與 Notion 指令
渲染 Manim 場景 (scripts/render.py)
# 快速草稿預覽(半解析度 15fps)
python3 scripts/render.py templates/character_rig_scene.py CharacterRigShowcase --quality draft
# 完整 1080p60 16:9 渲染
python3 scripts/render.py templates/stroke_drawing_morphing.py StrokeMorphShowcase --quality high
# 直式 9:16 (1080x1920), 3:4 (1080x1440), 或方形 1:1 (1080x1080) 60fps
python3 scripts/render.py my_scene.py MyScene --preset portrait --quality high
python3 scripts/render.py my_scene.py MyScene --preset square --quality high
# 透明疊層(含 Alpha 通道的 .mov,用於合成至影片上)
python3 scripts/render.py lower_third.py LowerThird --transparent --quality high
編輯、字幕、重構與組合影片 (scripts/video_edit.py)
# 檢查任何影片片段
python3 scripts/video_edit.py probe clip1.mp4 clip2.mp4
# 混合長寬比片段,使用 0.5 秒淡入淡出與模糊環繞寬螢幕填充
python3 scripts/video_edit.py combine clip1.mp4 square_clip.mp4 -o Combined.mp4 --preset landscape --xfade 0.5 --bg-mode blur
# AI 編輯:鏡頭偵測、Whisper 自動字幕、字幕燒錄、智慧 9:16 重構、節拍同步、音訊閃避
python3 scripts/video_edit.py detect-scenes raw.mp4 --out scenes.json --split-dir shots/
python3 scripts/video_edit.py auto-captions talk.mp4 -o captions.srt --json-out words.json --words
python3 scripts/video_edit.py burn-subtitles talk.mp4 --srt captions.srt -o captioned.mp4
python3 scripts/video_edit.py smart-reframe wide.mp4 -o reel_9x16.mp4 --preset portrait
python3 scripts/video_edit.py beat-markers music.mp3 --out beats.json
python3 scripts/video_edit.py duck-audio video.mp4 --voice narration.mp3 --music bgm.mp3 -o mixed.mp4
# 修剪、速度曲線、合成透明 Manim 疊層、混入音訊、或匯出 GIF
python3 scripts/video_edit.py trim in.mp4 -o cut.mp4 --start 2.0 --end 14.5
python3 scripts/video_edit.py speed in.mp4 -o fast.mp4 --factor 1.5
python3 scripts/video_edit.py overlay base.mp4 overlay.mov -o out.mp4
python3 scripts/video_edit.py mux-audio video.mp4 music.mp3 -o final.mp4 --volume 0.35 --fade-out 1.5
python3 scripts/video_edit.py gif final.mp4 -o preview.gif --fps 24 --width 720
與 Notion 同步 (scripts/notion_sync.py 或已連接的 Notion 應用程式)
export NOTION_TOKEN="ntn_..."
python3 scripts/notion_sync.py search "Video Roadmap"
python3 scripts/notion_sync.py read-page <PAGE_ID> --out brief.md
python3 scripts/notion_sync.py query-db <DB_ID> --out metrics.json
python3 scripts/notion_sync.py create-page --parent-db <DB_ID> --title "Launch Reel" --status "Draft" --body-file storyboard.md
python3 scripts/notion_sync.py update-status <PAGE_ID> --prop Status --value "Rendered"
python3 scripts/notion_sync.py log-render <PAGE_ID> --video out.mp4 --notes "1080p60 final"
關鍵陷阱
-qh會重設自訂尺寸: 渲染直式(1080x1920、1080x1440)或方形(1080x1080)場景時,切勿傳遞-qh;請使用scripts/render.py --preset ...或-r WIDTH,HEIGHT --fps 60,並在construct()中將self.camera.frame_width/frame_height設為與目標長寬比相符。- 僅使用無衝突安裝: 切勿混合
opencv-python+opencv-python-headless、pygame+pygame-ce、manim+manimgl,或pip install ffmpeg(請使用imageio-ffmpeg/ 系統二進位檔)。 faster-whisper音訊解碼: 在傳遞給WhisperModel.transcribe(...)之前,務必先透過ffmpeg將音訊預先解碼為 16 kHz 單聲道float32(video_edit.py auto-captions會自動處理此步驟)。MovingCameraScene相機更新器: 務必在self.camera.frame.add_updater(track_cam)之前呼叫self.add(self.camera.frame),並使用基於dt的平滑處理(1.0 - np.exp(-k * dt)),以便 15fps 草稿與 60fps 渲染的追蹤行為一致。- 旋轉角色臀部錨點: 當
abs(body_spin) > 0.02時,切勿計算hip_h = -min(l_foot_y, r_foot_y);在 360°/720° 翻轉期間保持固定的直立hip_h,以免頭部陷入地板。 AnnularSector中心放置: 直接傳遞arc_center=center,而不是使用.move_to(center)(後者會對齊邊界框中心)。ffmpegxfade時間基準: 在鏈結xfade之前,將fps=60,settb=1/60,format=yuv420p放置在每個輸入分支的末端(特別是在overlay之後)。- 3D HUD 與零 LaTeX 軸: 在
ThreeDScene中,對 2D HUD 元素呼叫self.add_fixed_in_frame_mobjects(...);在Axes、BarChart和ThreeDAxes中傳遞axis_config={"label_constructor": Text}。