Skip to content

rohitg00/manim-video-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

78 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Manim Video Generator - Motia Edition 🎬

A Manim animation generator rebuilt with Motia - the event-driven backend framework. This version demonstrates how to structure a video generation pipeline using Motia's Step primitives.

manim video generator

Detailed Step-by-Step Guide available here

Architecture

This application uses Motia's event-driven architecture to process animation requests asynchronously:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   GenerateApi   │────►│  AnalyzeConcept  │────►│   GenerateCode  β”‚
β”‚  (API Step)     β”‚     β”‚  (Event Step)    β”‚     β”‚  (Event Step)   β”‚
β”‚ POST /api/gen   β”‚     β”‚  LaTeX/template  β”‚     β”‚  AI or template β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                          β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
                        β”‚   StoreResult    │◄──────────────
                        β”‚  (Event Step)    β”‚              β”‚
                        β”‚  Stores results  β”‚              β–Ό
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                β–²                β”‚   RenderVideo   β”‚
                                β”‚                β”‚  (Event Step)   β”‚
                                └────────────────│  Runs Manim CLI β”‚
                                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  JobStatusApi   β”‚
β”‚  (API Step)     β”‚
β”‚ GET /api/jobs/* β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Event Flow

  1. animation.requested - Client submits concept via POST /api/generate
  2. concept.analyzed - Concept analyzed (LaTeX? Template match? Need AI?)
  3. code.generated - Manim Python code generated
  4. video.rendered / video.failed - Video rendered or error occurs
  5. Client polls GET /api/jobs/:jobId until complete

Project Structure

β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ generate.step.ts      # POST /api/generate
β”‚   β”‚   β”œβ”€β”€ job-status.step.ts    # GET /api/jobs/:jobId
β”‚   β”‚   └── refine.step.ts        # POST /api/refine
β”‚   β”œβ”€β”€ events/
β”‚   β”‚   β”œβ”€β”€ analyze-concept.step.ts
β”‚   β”‚   β”œβ”€β”€ generate-code.step.ts
β”‚   β”‚   β”œβ”€β”€ render-video.step.ts
β”‚   β”‚   └── store-result.step.ts
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ job-store.ts          # State management
β”‚   β”‚   β”œβ”€β”€ manim-templates.ts    # Pre-built templates
β”‚   β”‚   β”œβ”€β”€ openai-client.ts      # AI code generation
β”‚   β”‚   β”œβ”€β”€ nlu-classifier.ts     # Intent classification
β”‚   β”‚   β”œβ”€β”€ scene-composer.ts     # Scene graph builder
β”‚   β”‚   β”œβ”€β”€ prompt-engine.ts      # Multi-stage prompting
β”‚   β”‚   └── style-presets.ts      # Visual style configs
β”‚   └── types/
β”‚       β”œβ”€β”€ nlu.types.ts          # NLU type definitions
β”‚       └── scene.types.ts        # Scene graph types
β”œβ”€β”€ skills/                       # Animation skills
β”‚   β”œβ”€β”€ math-visualizer/
β”‚   β”œβ”€β”€ animation-composer/
β”‚   β”œβ”€β”€ visual-storyteller/
β”‚   └── motion-graphics/
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ index.html                # Frontend UI
β”‚   └── videos/                   # Generated videos
β”œβ”€β”€ motia.config.ts               # Motia configuration
β”œβ”€β”€ package.json
└── tsconfig.json

Setup

Prerequisites

  • Node.js 18+
  • Python 3.10+
  • Manim Community Edition
  • FFmpeg
  • LaTeX distribution (texlive)

Installation

# Navigate to motia directory
cd motia

# Install dependencies (will run motia install via postinstall)
npm install

# Add OpenAI and UUID dependencies
npm install openai uuid zod

# Configure environment
cp .env.example .env
# Edit .env with your OpenAI API key

# Generate types
npm run generate-types

# Start development server
npm run dev

Environment Variables

# Required
OPENAI_API_KEY=your-openai-api-key

# Optional
OPENAI_MODEL=gpt-4o-mini    # Default model for code generation

Usage

  1. Start the server: npm run dev
  2. Open http://localhost:3000
  3. Enter a mathematical concept or LaTeX expression
  4. Click "Generate Animation"
  5. Wait for the video to render (poll status automatically)

API Endpoints

POST /api/generate

Start animation generation.

{
  "concept": "Demonstrate the Pythagorean theorem",
  "quality": "low"
}

Response:

{
  "success": true,
  "jobId": "uuid",
  "status": "processing"
}

GET /api/jobs/:jobId

Check job status.

Response (completed):

{
  "jobId": "uuid",
  "status": "completed",
  "video_url": "/videos/uuid.mp4",
  "code": "from manim import *...",
  "used_ai": false,
  "render_quality": "low"
}

Natural Language to Animation

The generator uses an NLU (Natural Language Understanding) pipeline to transform natural language into animations:

User Input β†’ NLU Classifier β†’ Scene Composer β†’ Prompt Engine β†’ Manim Code β†’ Video

Skills System

Install animation skills for enhanced generation:

# Using SkillKit (Recommended) - Install all skills
npx skillkit install rohitg00/manim-video-generator/skills

# Or install individual skills
skillkit install rohitg00/manim-video-generator/skills/math-visualizer
skillkit install rohitg00/manim-video-generator/skills/motion-graphics
skillkit install rohitg00/manim-video-generator/skills/animation-composer
skillkit install rohitg00/manim-video-generator/skills/visual-storyteller

# Using skills.sh (alternative)
npx skills add rohitg00/manim-video-generator/

Available skills:

  • math-visualizer - Equations, proofs, graphs, geometric concepts, concept decomposition
  • animation-composer - Multi-act scenes, transitions, camera control, scene planning, layout validation
  • visual-storyteller - Step-by-step explanations, narratives, CLEAR framework, process visualization
  • motion-graphics - Kinetic typography, logos, title sequences, audio sync, web export, thumbnails
  • shared - Core animations library, easing reference (used by all skills)

Style Presets

Choose a visual style when generating:

{
  "prompt": "Visualize the Pythagorean theorem",
  "style": "3blue1brown"
}

Available styles: 3blue1brown, minimalist, playful, corporate, neon

Refinement API

Iteratively refine generated animations:

curl -X POST http://localhost:3000/api/refine \
  -H "Content-Type: application/json" \
  -d '{"jobId": "uuid", "refinement": "make colors warmer", "preserveElements": true}'

Supported Topics

  • Pythagorean theorem
  • Quadratic functions
  • Trigonometry (unit circle)
  • 3D surface plots
  • Sphere/Cube geometry
  • Derivatives & Integration
  • Matrix operations & Eigenvalues
  • Complex numbers
  • Differential equations

πŸŽ₯ Showcase

Here are some examples of complex mathematical animations generated using our tool:

Complex Analysis Visualization

Complex Number Transformations

This animation demonstrates complex number transformations, showing how functions map points in the complex plane. Watch as the visualization reveals the geometric interpretation of complex operations.

3D Calculus Concepts

3D Surface Integration

A sophisticated 3D visualization showing multivariable calculus concepts. The animation illustrates surface integrals and vector fields in three-dimensional space, making abstract concepts tangible.

Differential Equations

Differential Equations

This animation brings differential equations to life by visualizing solution curves and phase spaces. Watch how the system evolves over time, revealing the underlying mathematical patterns.

Linear Algebra Transformations

Linear Transformations

Experience linear transformations in action! This visualization demonstrates how matrices transform space, showing concepts like eigenvectors, rotations, and scaling in an intuitive way.

These examples showcase the power of our tool in creating complex mathematical visualizations. Each animation is generated from a simple text description, demonstrating the capability to:

  • Render sophisticated 3D scenes with proper lighting and perspective
  • Create smooth transitions between mathematical concepts
  • Visualize abstract mathematical relationships
  • Handle multiple mathematical objects with precise timing
  • Generate publication-quality animations for educational purposes

Why Motia?

The original Flask app handled everything synchronously. With Motia:

  1. Async Processing - Long-running renders don't block the API
  2. Event-Driven - Each step is decoupled and independently scalable
  3. Type Safety - Zod schemas validate inputs/outputs
  4. Observability - Built-in tracing via Motia Workbench
  5. Multi-Language - Python steps can be added alongside TypeScript

Deployment

Docker (Local/Self-Hosted)

# Build and run with docker-compose
docker-compose up -d

# Or build manually
docker build -t manim-generator-motia .
docker run -p 3000:3000 \
  -e OPENAI_API_KEY=your-key \
  -v $(pwd)/public/videos:/app/public/videos \
  manim-generator-motia

Sevalla Deployment

  1. Connect Repository: Link your GitHub repo to Sevalla
  2. Configure Build:
    • Build Command: npm run build
    • Start Command: motia start
    • Dockerfile Path: motia/Dockerfile
  3. Set Environment Variables:
    • OPENAI_API_KEY - Your OpenAI API key
    • OPENAI_MODEL - (optional) gpt-4o-mini
    • NODE_ENV - production
  4. Deploy: Sevalla will build and deploy automatically

Frontend-Backend Connection

The frontend (public/index.html) is served by Motia from the same origin as the API:

  • Frontend: Served at / (root)
  • API Endpoints: /api/generate, /api/jobs/:jobId
  • Generated Videos: /videos/*.mp4
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Motia Server                     β”‚
β”‚                  (port 3000)                        β”‚
β”‚                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   Express   β”‚    β”‚     Motia Steps             β”‚ β”‚
β”‚  β”‚  Middleware β”‚    β”‚                             β”‚ β”‚
β”‚  β”‚             β”‚    β”‚  /api/generate β†’ GenerateApiβ”‚ β”‚
β”‚  β”‚  GET /      β”‚    β”‚  /api/jobs/*  β†’ JobStatusApiβ”‚ β”‚
β”‚  β”‚  (index.html)    β”‚                             β”‚ β”‚
β”‚  β”‚             β”‚    β”‚  Events:                    β”‚ β”‚
β”‚  β”‚  /videos/*  β”‚    β”‚  β†’ AnalyzeConcept           β”‚ β”‚
β”‚  β”‚  (static)   β”‚    β”‚  β†’ GenerateCode             β”‚ β”‚
β”‚  β”‚             β”‚    β”‚  β†’ RenderVideo              β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Multi-Instance Scaling

For horizontal scaling, configure Redis adapter in motia.config.ts:

import { config } from 'motia'

export default config({
  adapters: {
    state: {
      type: 'redis',
      options: { host: 'redis', port: 6379 }
    },
    events: {
      type: 'redis',
      options: { host: 'redis', port: 6379 }
    }
  }
})

Development

View the workflow in Motia Workbench:

npm run dev
# Open http://localhost:3000/workbench

Health Check

The app exposes a health endpoint for container orchestration:

curl http://localhost:3000/health
# {"status":"healthy","timestamp":"2024-..."}

🀝 Credits

πŸ”— Links

License

MIT License - See LICENSE for details.

About

This application allows you to generate mathematical animations using natural language descriptions. It uses OpenAI's GPT model to convert your descriptions into Manim code, which is then used to create beautiful mathematical animations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Β 
Β 
Β 

Contributors