कर्मण्येवाधिकारस्ते मा फलेषु कदाचन।
मा कर्मफलहेतुर्भूर्मा ते सङ्गोऽस्त्वकर्मणि॥

You have a right to the work alone, never to its fruits. Do not let the fruit be your motive, and do not cling to inaction.
— Bhagavad Gita 2.47

It started with my feed. For a couple of weeks, X and Instagram were a flood of reels and explainers that all carried the same caption: made with Fable 5.2. Animated explainers, mini documentaries, whole storyboards, and under each one somebody saying they had built it over a weekend. I watched far too many of them before admitting the obvious. I did not want to watch any more. I wanted to try my own hands on Fable 5.2.

The only question was what to make. I am of Indian heritage, so the answer took about four seconds: the Mahabharata, the greatest and the biggest of the Indian epics. It runs to roughly a hundred thousand verses, about ten times the Iliad and the Odyssey put together, and at its centre is an eighteen-day war that I have heard told since I was a child. If a model was going to be tested on storytelling, I wanted to test it on the story I know best. Go big or go home, and the Mahabharata is as big as it gets.

So I made a 20-episode animated series on that war, about four and a quarter hours of video, and at no point did I drag a clip onto a timeline. There is no Premiere project. There is no After Effects file. There is a folder of Python scripts, some HTML, five music tracks, and a very patient laptop.

Arjuna and Karna trade divine weapons from their chariots, a few seconds of Episode 18

The series is called Mahabharata: The Eighteen Days. Episode 1 is the Bhagavad Gita, Krishna's teaching to Arjuna on the morning of the battle. Episodes 2 to 19 are the eighteen days of the war, one day each, and Episode 20 is what came after. Narration is in Hindi, subtitles are in English, and every single thing on screen is drawn by code.

That includes this, from Episode 1: the Vishvarupa, the moment Krishna shows Arjuna his universal form. Every arm, face and planet is SVG written by a Python script.

The Vishvarupa: Krishna's universal form, with Arjuna kneeling before it

दिवि सूर्यसहस्रस्य भवेद्युगपदुत्थिता।
यदि भाः सदृशी सा स्याद्भासस्तस्य महात्मनः॥

If the light of a thousand suns were to blaze out at once in the sky, that might resemble the splendour of that great being.
— Bhagavad Gita 11.12

All twenty episodes are on YouTube. Here is Episode 1, and the full playlist is here.

This post is the nerdy version of how it works: the setup, every library and model and what it is for, how each piece gets made, the bugs that ate my evenings, and the episode list at the end.

The code is on GitHub: amananandrai/mahabharata-eighteen-days. It has the whole engine and one complete episode as a worked example, so you can build and render it yourself.

What's in this post

  • The one idea that makes it possible
  • The setup
  • The models, and who does what
  • The libraries, in a bit more detail
  • How each thing is made
  • War stories
  • Where Fable 5.2 needed a human
  • The numbers
  • What I would tell you over chai
  • The twenty episodes

The one idea that makes it possible

A video is just a web page that changes over time.

If a frame is HTML, then a character is a function, a chariot duel is a function, and an episode is a list of function calls. Fixing a wrong shot means changing one line and rebuilding. Nothing is redrawn by hand, ever. That is the only reason one person can ship twenty episodes.

A disclosure, since it matters: I did not hand-write most of this code. I worked with Claude Code as a coding agent. I gave direction, taste and corrections ("chariots always have horses", "the conch is the wrong way round", "why is that elephant underground"), and it wrote the Python, HTML and JavaScript. Think of me as the director and it as a tireless art department that never asks for chai.

The setup

Everything runs on one Windows laptop. Here is the whole stack.

Tool Version I used What it does here
Claude Code desktop app, on the Max plan The coding agent. Wrote and ran nearly all the code
Claude Opus, Claude Fable Fable 5.2 for the later episodes The models behind Claude Code
HyperFrames 0.9.88 to 0.9.96 Renders HTML + animation timelines to MP4
GSAP 3.15.0 The animation timeline inside every scene
p5.brush 3.0.0, patched Ink and watercolour brushwork for maps, formations, verses
Sarvam Bulbul bulbul:v4-flash Hindi text-to-speech, the narrator
Lyria 3 (in the Gemini web app) Generated the five background music tracks, at no cost
ffmpeg 9.0 Joins sections, mixes audio, makes contact sheets
Python 3.13 Draws characters and props, builds episodes
Node.js 24 Runs the HyperFrames CLI
numpy + soundfile Stitches the narration audio

Fonts are Rozha One for the big Hindi titles and Tiro Devanagari Sanskrit for verses, both open-licensed.

The project folder is boring on purpose (the repo has the same layout):

Mahabharata-Series/ scripts/ the 20 narration scripts, the 20 shot lists, and the build tools shared/ characters, props, backdrops, fonts, music, two small JS libraries episodes/ one folder per episode: voice, sections, final MP4 .env the TTS API key (never committed, never printed) 

The models, and who does what

Four AI models are involved, and they have strictly separate jobs. None of them draws a picture.

Claude (Opus and Fable), through Claude Code. This is the engineer. It wrote the drawing code, the episode builder and the shot lists, ran the builds, looked at the review frames, and fixed what was wrong. It also loads skills, which are packaged instructions for a specific tool. The HyperFrames skills (hyperframes, hyperframes-cli) are what taught it the render contract and the CLI, so I never had to paste documentation into a chat.

Sarvam Bulbul v4, for the voice. One narrator for the entire series, the voice Aditya (aditya_hi_conversational), at pace 0.9 and temperature 0.5, 48 kHz. I picked one voice and refused to change it. Twenty episodes in one voice feel like one telling; twenty episodes in five voices feel like a group project.

It is also absurdly cheap. Narrating the entire series, all twenty episodes, came to 169,000 characters and ₹338.01 on my Sarvam bill. That is about ₹2 per thousand characters, roughly ₹17 an episode, or about $3.71 at ₹91 to the dollar, for four and a quarter hours of narration. I have paid more than that for a single disappointing sandwich.

Lyria 3, through Gemini, for the music. I generated five instrumental tracks and gave each a job:

Track Used for
Call of the Sacred Valley Series theme, title card, divine moments
Where the River Bends Storytelling, recaps, backstories, palace scenes
Before the Final Charge Battle and duels
Where Kings Once Fell Death and grief
Lotus Petals on the Current The Gita, Krishna, reflection

Five tracks for four hours sounds stingy. It works because the music sits low under the voice and each track always means the same thing. By Episode 6 you hear the first bars of "Where Kings Once Fell" and you already know someone is not making it to sunset.

No image model at all. Every face, horse and tent is SVG that Python writes. That was a deliberate choice: a generated image of Bhishma looks different every time, and a function called bhishma does not.

The libraries, in a bit more detail

HyperFrames: the renderer

HyperFrames is an open-source framework from HeyGen that turns an HTML page with a paused animation timeline into a video. It opens the page in a headless browser, seeks the timeline to frame 0, takes a picture, seeks to frame 1, takes a picture, and so on, then encodes the lot.

The contract is simple: your page must look exactly the same every time it is asked for time t. No wall clock, no Math.random(), no "it'll settle in a moment". In return you get frame-exact video from plain web tech.

I use two commands, over and over:

npx hyperframes snapshot --at 12.5,30 # a PNG of the scene at those seconds npx hyperframes render --quality looks -o out.mp4 

GSAP: the clock

Every scene has one paused GSAP timeline, and every movement is added to it at an absolute time. A walk, an arrow, a blink, a camera push: all entries on the same timeline. HyperFrames just seeks it.

p5.brush: the ink

p5.brush imitates real brushes and watercolour in the browser. I use it for battle formations, maps and Sanskrit verse cards, drawn stroke by stroke while the narrator speaks.

Out of the box it is not deterministic, which the renderer cannot tolerate. So the copy in the project has two small patches: Math.random is replaced by a fixed sequence, and the seed is reset on every frame. Same frame in, same pixels out.

ffmpeg: the glue

ffmpeg does four jobs: it joins the rendered sections, mixes narration with music, grabs frames for review, and tiles those frames into contact sheets. The final mix is one filter graph (more on that below).

Two tiny libraries of my own

These two are not downloads. They were written for this series, by Claude Code like the rest of the code, and they live in the repo under shared/lib.

  • rig.js (about 100 lines) moves the jointed characters: pose changes, walking, breathing, blinking, speaking, expressions. It is not even written by hand: draw_characters.py generates it, so the table of poses in the JavaScript always matches the joints in the drawings.
  • brush-kit.js (about 350 lines) wraps p5.brush with things the series needs: vyuha("krauncha") for a formation, moveArrow, underline, titleBloom, inkWipe. It also holds the stroke lists for all fifteen formations.

How each thing is made

An episode goes from a text file to an MP4 in seven steps.

  1. Write the Hindi script.
  2. Voice it and get the timing of every line.
  3. Write the shot list.
  4. Build the scenes.
  5. Review one frame of every shot.
  6. Render.
  7. Merge with narration and music.

Steps 4 to 7 are one command each.

1. The script

All twenty scripts were written before the first frame existed, so the series has one arc and each episode can tease the next. A script is a plain text file of about 1,600 Hindi words:

# भीम की प्रतिज्ञा [ADITYA] भीम ने गदा उठाई, और रथ से कूद पड़े। एक ही युद्ध में, धृतराष्ट्र के आठ पुत्र भीम की गदा के आगे धराशायी हो गए। [PAUSE 1.5] 

# starts a section, [ADITYA] names the speaker, each line is one narration line, and [PAUSE n] is where the music gets to breathe.

2. The voice, and the timing file

narrate.py sends each line to Sarvam, stitches the returned audio with short gaps, and writes two files: one WAV, and a segments.json like this:

{ "start": 252.4, "end": 262.1, "speaker": "ADITYA", "section": "भीम की प्रतिज्ञा", "text": "..." } 

That timing file is the spine of everything. Shots and subtitles are placed from those numbers, so the pictures cannot drift from the voice. I have never manually synced anything, and I intend to die that way.

3. Characters, drawn from a description

Every character is a small Python dict:

dict(id="bhagadatta", hi="भगदत्त", en="Bhagadatta", role="old king of Pragjyotisha · rider of Supratika", skin="#C29A78", hair="#EDEAE3", hair_back="long", beard="long", crown="royal", armour="#2C4F8C", cloth="#8E2A1E", weapon="spear", age="old") 

draw_characters.py reads that and writes SVG. There are functions for each part (hair_back, crown, beard, features, body, weapon), and each one looks at the dict and draws accordingly. A crown of type "royal" is one path, "sun" is another, and Karna gets rays.

The ten main characters as close-up busts, each with a name card

From one description the script draws three views: a close-up bust, a front-view full figure, and a side-view figure for chariots and duels.

Full-figure versions of Krishna, Arjuna, Bhishma, Karna, Duryodhana and Bhima

The cast ended at about 180. That sounds like a lot of drawing until you see how a minor character is made:

_variant("susharma", id="sudakshina", hi="सुदक्षिण", en="Sudakshina", role="king of Kamboja", cloth="#6A2A4A", armour="#4A3A4A") 

A king who appears for eleven seconds before Arjuna ends his career is one line. The eight sons of Dhritarashtra who die on Day 4 took a few minutes in total.

4. Making them move

The figures are jointed. Shoulders, elbows, hips, knees, head, weapon and eyelids are separate SVG groups with predictable ids, so a figure can glide from one pose to another.

Side views, the side poses (aim, strike, hit, bow, kneel, slump, heave, drive) and the expressions

There are fifteen front poses and about ten side poses, plus five expressions (usual, anger, grief, joy, awe). The rig library puts all of it on the GSAP timeline:

Rig.to(tl, "arjuna-rig-", "aim", 2.0, 0.8); // at 2.0 s, move into the aim pose over 0.8 s Rig.idle(tl, "arjuna-rig-", 0, 12); // breathing and blinking Rig.walk(tl, "krishna-rig-", 1.4, 4.6); // legs step while the figure slides across Rig.face(tl, "bhima-rig-", "anger", 3.0); Rig.speak(tl, "krishna-rig-", 5.0, 9.5); // mouth moves while his line is narrated 

Front poses for Arjuna and Bhima: stand, aim or strike, namaste, command, grief, seated

5. Props, chariots and backdrops

Props come from a second script, draw_assets.py, in the same style: horses in three coats, a chariot per hero with his own banner, war elephants, cavalry, foot soldiers, swords, shields, tents, torches, a throne, a dice board.

Props and scenery: horses, chariots with each hero's banner, cavalry and soldiers, weapons, backdrop layers and tents, painted scenes

A manned chariot is assembled on demand. Ask for Karna with Shalya driving and the builder puts both side-view figures into Karna's chariot behind four horses, and caches the result. Pandava-side warriors get white horses and Kaurava-side warriors get brown, because by Episode 13 I had been corrected on that exactly once and once was enough.

Full scenes (the two camps, the throne room, the dice hall, the palace, a river bank, a forest) are also code. They are drawn once and baked to flat PNGs, so the renderer is not redrawing four hundred tiny soldiers on every frame.

The Pandava camp at night, a baked backdrop

6. Brush scenes

Formations, maps and verses are painted live with p5.brush on a parchment card. Each day's battle arrays get their own brush drawing, and name tags mark who stood at the beak, the eyes and the wings.

The fifteen battle formations as brush drawings, from the thunderbolt to the Chakravyuha

Here are two of them being painted, a few seconds of Episode 17:

The crocodile and half-moon formations being painted stroke by stroke

In a scene it is a few calls:

const layer = BrushKit.layer("paper-host", { paper: "#E9D3A0" }); layer.add(BrushKit.vyuha("krauncha", { x: 620, y: 560, size: 330, start: 1, end: 4 })); layer.add(BrushKit.moveArrow([[700,560],[1000,540]], { start: 4.5, end: 5.5 })); layer.bind(); // listens to the HyperFrames clock 

7. The shot list, where the directing happens

This is the part that needs a human brain, or at least a brain. Each episode has a shot list with one entry per narration line, and each entry names one to five shots and their share of that line's time. An episode has 70 to 80 lines and 110 to 150 shots.

Here is the entry for "Bhima raised his mace, and leapt down from the chariot":

[("chariotduel", 1, dict(lfoot=("bhima", "s-strike", "anger"), lx=240, r=("kaurava-1",), rpose="s-stand", arrows=0, acts=[("walk", "L", 0.1, 0.95, 560)]))] 

Read aloud: a chariot scene; Bhima on foot on the left, mace raised, angry; a Kaurava prince standing in his chariot on the right; no arrows; Bhima walks towards him for most of the shot.

One shot, start to finish

Here is a whole shot, from sentence to screen. It is the cold open of Episode 18: Karna's chariot wheel has sunk into the earth, and he has got down to free it.

The narration line, as it sits in the script:

उसने अर्जुन की ओर देखा, और कहा — अर्जुन, रुको। मैं निहत्था हूँ। मेरा रथ फँसा है। धर्म कहता है, ऐसे योद्धा पर वार नहीं किया जाता। 

Its English subtitle: He looked at Arjuna and said: Arjuna, wait. I am unarmed. My chariot is stuck. Dharma says such a warrior is not to be struck.

Its entry in the shot list:

("chariotduel", 1, dict( l=("arjuna", "krishna"), lpose="s-stand", # Arjuna's chariot, Krishna driving r=("karna", "shalya"), rpose="s-stand", # Karna's chariot, Shalya driving empty="R", # ...but Karna himself is not in it sunk=("R", None), # and it tilts, one wheel in the earth extra=[("K", "karna", "s-heave", 1480, "grief", dict(weapon=None))], # he is on foot, unarmed arrows=0, bg="dusk", acts=[("to", "K", "s-stand", 0.1, 0.4), # he straightens up from the wheel ("speak", "K", 0.2, 0.98)])) # and speaks for the rest of the shot 

And the frame that comes out:

The finished frame: Karna standing by his tilted chariot, Arjuna and Krishna facing him, the subtitle "I am unarmed"

Nobody placed Karna there with a mouse. The sentence became a few lines of data, and the data became the picture. The sunk and empty options did not exist until this episode needed them.

The vocabulary grew to about thirty shot types:

Shot type What it shows
close One face, with an expression, speech and an optional name card
pair Two people in profile, talking or fighting on foot
lineup Several figures in a row, optionally named
chariotduel Two manned chariots, arrows crossing and meeting in sparks
charge Cavalry or elephants sweeping across the field
still A painted scene with a slow camera move, optional fire or rain
text One line of Hindi on a dark card, English below
vyuha, map, route, shloka The brush scenes
giant, night, bed Ghatotkacha's sorcery, the torch-lit field, Bhishma on his bed of arrows

New options were added only when the story demanded them, and then every later episode got them for free. Day 4 needed a war elephant in place of a chariot. Day 15 needed Yudhishthira's chariot to float just above the ground and drop when he tells his one half-truth. Day 17 needed Karna's chariot to tilt as its wheel sinks. The finale needed a dog, and the only dog I had was one with seven arrows in its mouth from an earlier backstory, which is not the vibe for a loyal companion walking to heaven. So the finale got a new dog.

8. Build

build_episode.py reads the shot list and the timing file and writes one small HyperFrames project per script section: the cold open, the recap, each story. Each is 20 to 110 seconds. Subtitles are generated from the same data.

Sections matter. A crash or a late fix costs one section, not the episode.

9. Review every shot before rendering

Rendering takes about an hour, so a wrong shot found afterwards is expensive. Before any render, one command captures a frame from every shot, with its subtitle, and tiles them nine to a sheet with ffmpeg. An episode is thirteen to seventeen sheets, and reading them in order is like reading the storyboard of the finished film.

This is a real one, the first sheet of Episode 18. Each tile is one shot with the subtitle it plays under:

A contact sheet: nine shots from the opening of Episode 18, each with its subtitle

You read it left to right like a comic strip and ask one question of every tile: does the picture match the words?

And these are finished frames from the last four episodes:

Six finished frames from Episodes 17 to 20

This check is where most of the comedy lives. Things it caught:

  • A love story set in Dwaraka was playing out in front of two armies.
  • Bhima vanished inside his own chariot when an arrow hit him.
  • An elephant stood slightly below ground level.
  • Arjuna, heroically guarding his exhausted horses, was aiming his bow straight at Krishna.
  • Karna, whose wheel had sunk, was tugging at his horses instead.
  • A weapon "that covered the sky" showed two arrows. It is now seventy.

A few house rules came out of these reviews and now apply everywhere: chariot warriors fight from chariots unless the story puts them on foot; a chariot always has its horses; figures in a chariot are whole figures, never half bodies; anything that walks stands on the ground; and if a scene is simplified, the simplification is written down in the shot list, not hidden.

10. Render

Each section is rendered by HyperFrames in a headless browser, at roughly three to six seconds of work per second of video. A small PowerShell script loops over the sections and skips any that are already up to date, so an interrupted render just resumes.

11. Merge: one ffmpeg graph

The last step joins the sections with the concat demuxer (no re-encode), then builds the soundtrack. A plan file assigns a music track to every section of every script; the merge script turns that into delayed, volume-set music inputs and mixes them under the voice:

[1:a]volume=-22dB,adelay=33000:all=1[m0]; [2:a]volume=-22dB,adelay=42000:all=1[m1]; [0:a]volume=0dB[v]; [v][m0][m1]amix=inputs=3:normalize=0:duration=longest, loudnorm=I=-16:TP=-1.5:LRA=11,aresample=48000[a] 

Music sits at -22 dB under narration, rises to -10 dB in pauses, and crossfades over two seconds when the mood changes. loudnorm brings every episode to the same loudness, which is why every one I measured sits at about -16.6 dB mean volume. Audio is AAC at 192 kbps and the file gets +faststart so it streams immediately.

War stories

The 61-minute formation

Around Episode 8, one 41-second brush scene took 61 minutes to render. I blamed circles (the slow formations had circles). Then I blamed heat. Both theories were confident and wrong.

The real cause: the brush layer repainted the entire painting on every one of 30 frames a second, even when nothing had changed. The fix was two ideas and about ten lines:

t = Math.floor(t * fps + 1e-6) / fps; // draw brushwork at 10 fps if (signature === layer._sig) return; // nothing new to paint? keep the last canvas 

Brushwork at ten frames a second looks more hand-made, not less, and the same kind of scene now renders in about five minutes. Lesson: time one thing in isolation before you build a theory about it.

The release that broke my render

During Episode 15, renders started failing in two seconds flat. A new HyperFrames version had been published minutes earlier and was not installable from npm yet, and the launcher wanted the latest. Pinning the previous version fixed it:

$env:HYPERFRAMES_STANDALONE_CLI_VERSION = '0.9.96' 

Pin your tools. You will not remember this advice until the night you need it.

The disk that kept filling up

Each episode's working files are about 1.4 GB, and my laptop was not built for twenty of those. So every episode gets cleaned once its video is final: the rendered sections and review sheets go, and only the MP4, the narration audio and the shot list stay. A finished episode folder is about 0.6 GB.

Where Fable 5.2 needed a human

I came here because of the hype, so here is the unhyped part. Fable 5.2 wrote a lot of good code very fast. It also got things wrong in ways that were consistent enough to plan around.

  • It cannot watch its own video. It looks at stills. A frame can be perfect while the motion around it is off, and it will never know. Inside a narration line that has several shots, the subtitle and the picture can drift apart by a beat, because shots are split by weight and subtitles by text. It offered to fix that. I never took it up, and it is still there.
  • It places things blind. A shot is written as coordinates before anything is drawn. That is how Arjuna ended up aiming at Krishna, an elephant sank into the ground, name tags landed on top of the formations they were naming, and Karna pulled at his horses. Every one was fixed in a minute once a frame was captured. None would have been caught without the capture.
  • It is confidently wrong about causes. The slow renders were "because of circles", then "because of heat". Both explanations sounded excellent. The real cause turned up only when one section was timed on its own.
  • It does not know what matters to you until you say it. Chariots without horses, half a body sitting in a chariot, a conch held the wrong way round, a Pandava hero behind the enemy's brown horses. Nothing in the code was wrong. All of it was wrong on screen, and each became a house rule only after I complained.
  • Some things stayed stand-ins. There is no lying-down pose, so Duryodhana with his broken thigh kneels. Dhrishtadyumna "climbs onto Drona's chariot" by walking up beside it. The Himalaya is the battlefield in a pale tint. The model noted each of these in the shot list, which I appreciated, but a note is not a drawing.
  • Long sessions forget. After enough hours the conversation is summarised and details fall out. What saved the project was a plain plan file in the repo with the status, the rules and the lessons, which it re-read and kept up to date.

None of this is a complaint. It is the job description. The model is the art department; someone still has to be the director, and the review sheet is how the director gets to see the film before paying for it.

The numbers

Episode Length Shots Render time Final file
4 · Day 3 13.3 min 108 about 85 min 579 MB
5 · Day 4 12.5 min 138 about 95 min 513 MB
17 · Day 16 12.3 min 153 about 66 min 572 MB
18 · Day 17 12.5 min 150 about 52 min 575 MB
19 · Day 18 13.0 min 144 about 46 min 559 MB
20 · After the war 12.9 min 139 about 54 min 490 MB

The late episodes have more shots and still render in about half the time, thanks to the brush fix.

And this is what the whole series cost to make:

What Cost
Narration: Sarvam Bulbul, 169,000 characters ₹338.01 (about $3.71 at ₹91 to the dollar)
Music: Lyria 3, generated in the Gemini web app Free
Coding agent: Claude Code My Claude Max subscription
HyperFrames, GSAP, p5.brush, ffmpeg, Python Free and open source

So the only money that went out specifically for this series was the voice. Everything else was either free or a subscription I already had. The codebase is small: about 1,000 lines for the episode builder, 1,700 each for the character and prop drawing, and under 500 lines of JavaScript for the rig and the brush kit.

What I would tell you over chai

  • Write all the scripts first. The series has one arc because the twenty scripts existed before the first frame.
  • Let the voice set the timing. Pictures placed from the narration's timestamps never need syncing.
  • Build a small vocabulary and reuse it. The early episodes wer...