Code2Video: A Code-centric Paradigm for Educational Video Creation
Abstract
While recent generative models can synthesize videos in pixel space, they often fail to produce educational videos with precise structures, domain knowledge, and coherent transitions. We argue that this setting is better served by operating in a renderable environment that is explicitly controlled by code. We propose Code2Video, a code-centric agent framework that generates educational videos by writing executable Python programs. Code2Video includes three agents: a Planner that converts lecture content into a temporal storyboard, a Coder that turns the storyboard into runnable code with scope-guided auto-fix, and a Critic that refines layout using a VLM guided by visual anchor prompting, i.e., mappings from target visual outcomes to code edits. For evaluation, we build MMMC, a benchmark of professionally produced, discipline-specific educational videos. We assess Code2Video using aesthetic scores (VLM-as-a-Judge), code efficiency, and TeachQuiz, an end-to-end metric that measures how well an unlearned VLM can recover knowledge after watching generated videos. Code2Video improves performance by 40% over direct code generation and produces videos comparable to human-crafted tutorials. The code and datasets are available at https://github.com/showlab/Code2Video.
Lay Summary
Educational videos are hard for today's AI video generators because they need more than attractive visuals: they must present ideas in the right order, keep symbols and text accurate, and make each step easy to follow. Instead of generating every pixel directly, we ask AI to create these videos by writing computer code that controls the visuals. Our system, Code2Video, first plans the lesson as a storyboard, then writes runnable animation code, and finally checks and improves the layout so the video is clearer and more consistent. To evaluate this problem, we built a benchmark of high-quality educational videos across multiple subjects. We also designed a new test, TeachQuiz, which measures whether an AI viewer can actually recover knowledge after watching a generated video. Compared with direct code generation, our method improves results by about 40% and produces videos closer to human-made tutorials. This matters because it points to a more reliable way to build educational videos that are accurate, interpretable, and easier to control.