Code2Video: A Code-centric Paradigm for Educational Video Creation

Yanzhe Chen, Kevin Qinghong Lin, Mike Zheng Shou

TL;DR: Code2Video shifts the paradigm of educational video generation from "pixel-space" diffusion to "code-space" execution. By utilizing a tri-agent framework to write and refine executable Python code, it produces structured, mathematically accurate tutorials that outperform pixel-based models and rival human-crafted content in teaching efficacy.

The Problem: Pixels vs. Precision

While generative models like Sora or Runway can synthesize visually stunning videos, they are notoriously poor at logical reasoning and structural precision. For educational content—such as a 10-minute lecture on Fourier Transforms—precision is paramount. Pixel-based models frequently hallucinate mathematical symbols, struggle to maintain long-form coherence, and offer zero "editability." If a single formula is incorrect in a diffusion-generated video, creators cannot simply change a variable; they must regenerate the entire sequence.

Educational videos require temporal coherence (concepts building logically over time) and spatial clarity (elements arranged legibly without overlapping). The authors of Code2Video argue that these requirements are best met by treating video creation as a programming task rather than a frame-interpolation task. Code provides a deterministic, interpretable, and controllable bridge between a text prompt and a final video, bypassing the "black box" nature of diffusion.

The Code2Video Framework

To solve this, the researchers propose Code2Video, an agentic framework that generates educational videos by writing executable Python code for Manim (the animation engine popularized by the YouTube channel 3Blue1Brown). The system operates using three specialized agents:

  1. The Planner (Instructional Designer): Takes a topic, retrieves necessary assets from an external database, and creates a hierarchical, temporal storyboard.
  2. The Coder (Developer): Translates the storyboard into executable Manim code. To combat the high failure rate of LLM-generated code, it employs ScopeRefine (SR). This hierarchical debugging strategy fixes errors at the line or block level before attempting a full rewrite, saving significant time and computational tokens.
  3. The Critic (Art Director): Refines the visual layout using a Vision-Language Model (VLM). Because VLMs often struggle with precise spatial coordinates, the authors introduce Visual Anchor Prompting ($P_{vis}$). This technique discretizes the screen into a 6x6 grid, allowing the Critic to provide actionable feedback (e.g., "Move the formula from grid B2 to C4") rather than vague spatial descriptions.

Evaluation: MMMC Benchmark and "TeachQuiz"

To rigorously test this framework, the authors introduced MMMC (Massive Multi-discipline Multimodal Coding), a new benchmark curated from 117 long-form videos from the 3Blue1Brown channel. Covering 13 subject areas (from Calculus to Neural Networks) and segmented into 456 educational units, MMMC maps concise learning topics to high-quality, expert-level code and video.

Standard metrics like CLIP score or Fréchet Inception Distance (FID) measure how a video looks, not what it teaches. To address this, the authors developed TeachQuiz, an end-to-end metric utilizing a "selective unlearning" protocol. They force a VLM to "forget" a specific concept, show it the generated video, and then quiz it. If the VLM's score improves, the video successfully transferred knowledge.

Key Results

  • Superior Teaching Efficacy: Code2Video improved knowledge transfer (TeachQuiz) by 40% over direct code generation baselines. It vastly outperformed pixel-based models, which scored near zero on logic-heavy quizzes.
  • Aesthetic and Structural Gains: In human studies, Code2Video's outputs were preferred over strong baselines and were deemed competitive with professional, human-crafted tutorials.
  • High Efficiency: By breaking a video into sections and generating code in parallel, the framework reduces generation time from hours to minutes. Despite producing videos 15x longer than typical diffusion clips, the code-centric approach is 2.5–43x more efficient when normalized by output duration.
  • Robustness: The ScopeRefine debugging tool reduced token costs by up to 1.6x compared to naive "retry" strategies.

Limitations and Future Directions

While groundbreaking, the current system is tied to Manim, which is primarily a 2D engine. Moving toward backends like Blender or Unity could unlock 3D educational environments. Furthermore, code-generated videos are "clean" and "symbolic" but lack photorealistic textures. A hybrid approach—using code for structure and diffusion for "skinning" the visuals—presents a promising future direction. Finally, while the videos are mathematically accurate, future iterations will need to optimize for human attention spans and the nuanced storytelling that professional creators excel at to prevent perceptual fatigue.

Summary updated

BibTeX
@inproceedings{chen2026code,
  author = {Yanzhe Chen and Kevin Qinghong Lin and Mike Zheng Shou},
  title = {{Code2Video: A Code-centric Paradigm for Educational Video Creation}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=HJ0JFzdwUo},
}
Figure