I wrote code that makes my Instagram reels
, 2 min read, Automation, Python, Content, FFmpeg
Every CoderKing reel, from the Hinglish voiceover to the background music, comes out of a script. How a JSON file becomes a finished, ready-to-post video.
Editing reels by hand took me hours: record a voiceover, cut it, animate text, find music that won't get copyright-struck, add captions word by word. So I did what I always do with a boring task. I automated it.
CoderKing Studio turns a short script into a finished 1080×1920 reel with voiceover, motion graphics, word-by-word captions, sound effects and music. No editing app.
1. A reel is a list of beats
Each reel is written in Python as scenes made of beats. A beat has:
head: the big on-screen headline, with*stars*around the word that turns goldrom: the Hinglish subtitle people readdev: the same sentence in Devanagari, which is what the voice speakssteps: what the visuals do and when (show a node, draw an arrow, reveal a number)
The script checks that rom and dev have the same number of words, because the captions are timed word by word against the voice.
2. The voice, with timings
tts.py sends each beat to a neural text-to-speech voice (a free Hindi voice by default, ElevenLabs if I add a key) and asks for word boundaries: the exact time each word starts. Those timings drive the captions, so every word lights up as it's spoken. Beats are trimmed, spaced with a little breathing room, and laid on one timeline.
3. The visuals are a web page
All the motion graphics live in one HTML file with a render(t) function: give it a time in seconds, and it draws that exact frame. Puppeteer opens it in headless Chrome at 1080×1920 and screenshots 60 frames per second. FFmpeg blends pairs of frames down to 30 fps, which gives a natural motion blur.
Because frames are rendered from time, not from a running animation, a slow computer can't drop frames: it just takes longer.
4. Music and sound effects, from maths
I didn't want to worry about copyright, so mix.py synthesizes everything with NumPy: whooshes from filtered noise, pops and dings from sine waves, and a music bed with a four-chord progression, a soft kick and hi-hats. The music is "ducked", turned down automatically whenever the voice is speaking. FFmpeg normalizes the final mix to −14 LUFS, the loudness Instagram expects.
5. Ready to post
One more script copies the video into a dated folder with a cover image and a caption file: posting time, caption, five hashtags, search keywords and alt text.
What I learned
- Render from time, not from the clock. It makes video output deterministic and debuggable: any frame can be re-rendered on its own.
- Captions matter more than visuals. Most people watch with the sound off.
- Automation changes what you attempt. Ten reels used to be a month of work. Now it's an afternoon, and I spend that time on the scripts instead.
Follow along on @coderking__1, and try the experiments from the reels yourself.