# Make a music video drawn in code

A free prompt pack from Known Quantity LLC.

Every frame of these videos is drawn by a program, and everything on screen moves because the song tells it to. You do not need to be a programmer. You need a song, a computer, and an AI assistant that can write and run code. You describe what you want in plain words, and the assistant does the typing.

This pack gives you the method in six steps, a copy-paste prompt for each step, a checklist for checking your frames, and the honest limits.

---

## What you need

- **The song file.** A WAV or MP3 of music you have the rights to use. Your own music is perfect.
- **Python** (3.10 or newer) with **numpy**, an audio-reading library such as **librosa** or **soundfile**, and an image library such as **Pillow** or **pycairo**.
- **ffmpeg**, the free command-line tool that turns frames into a video and adds the sound.
- **An AI coding assistant that can write and run code on your machine** (or in a sandbox it controls). It needs to be able to open the pictures it makes, or show them to you.

If you have not installed any of this before, start with this prompt:

```
I want to make a music video where every frame is drawn in Python and reacts to the song.
Check whether Python 3.10+, numpy, librosa, Pillow and ffmpeg are installed on this machine.
Install whatever is missing, explain each step in one plain sentence, and finish by printing the version of each tool.
```

Keep everything for one video in one folder: the song, the code, the frames and the finished file.

---

## Step 1: Turn the song into numbers

The video can only follow the music if the music has been measured. This step listens to the song once and writes down, for every video frame, how loud it is, how much bass, middle and treble there is, where the beats land and where the song changes section.

```
Here is my song: [file name]. The video will be 1920x1080 at 30 frames per second.

Write and run a Python script that analyzes the song and saves one row of features per video frame (so 30 rows per second of audio) to a file I can reuse, such as features.npz.
For each frame, save:
- overall loudness (RMS), smoothed a little so it does not flicker
- bass energy (roughly 20 to 250 Hz), mids (250 Hz to 4 kHz) and highs (above 4 kHz)
- an onset or beat value that spikes when a drum hit or note starts, and decays quickly after
- the song's section boundaries (intro, verse, chorus, breakdown and so on), as a list of frame numbers where the character of the music changes
Scale every feature to 0 to 1 across the whole song so the quiet and loud parts both show up.

Then print a short summary: song length, number of frames, the loudest moment, the quietest moment, and the section boundaries in minutes and seconds. Save a simple chart of the four energy curves over time as a PNG and show it to me.
```

Look at the chart. You should be able to see the song in it: the drop, the quiet bridge, the big ending. If the curves are flat or all spikes, ask the assistant to change the smoothing before you go on.

---

## Step 2: Describe one scene, and let the music drive it

A scene is a function that draws one frame. You describe it in words. The rule that makes it a music video: **every movement comes from the music.** No timers, no random wobble that ignores the song.

```
Using features.npz from step 1, write a Python function draw_scene(frame_number, features) that returns one 1920x1080 image.

The scene: [describe it in plain words. For example: "a dark night sky over a still lake. Stars pulse with the highs. A low moon rises slowly through the song. Ripples spread across the lake on every beat, bigger when the bass is strong."]

Rules:
- Every motion and brightness change must come from the features: loudness, bass, mids, highs, beats. If something moves, tell me which feature moves it.
- Slow drifts are allowed only if they are tied to position in the song, not to a clock.
- Use a small palette of four to six colors. Keep the background dark so bright moments read.
- Keep it fast enough to draw one frame in under a second.
Write it so I can call it from a render script later. Do not render a video yet.
```

---

## Step 3: Render three test frames and look at them

This is the step people skip, and it is the one that saves you an hour. Before you render anything long, render three single frames from very different moments and look at them closely.

```
Render three still frames from draw_scene and save them as PNGs:
1. the loudest moment of the song
2. the quietest moment
3. the busiest moment (the most beats or onsets in a short window)
Show me all three side by side, with the time in the song under each one.
Then tell me honestly: does the quiet frame look calm and the loud frame look big? Is anything cut off at the edges, blown out to pure white, or too dark to see?
```

If the loud and quiet frames look nearly the same, the scene is not listening to the music. Say so, and ask the assistant to make the response stronger. Repeat until the three frames feel like three different moments of the song.

---

## Step 4: Build four to six scenes and a timeline

One scene for a whole song gets dull. Build four to six, and change scenes where the song changes.

```
Using the same rules as step 2, write [four / five / six] more scenes:
[describe each one in a sentence or two].

Then write a timeline that decides which scene plays when:
- change scenes only on the section boundaries found in step 1
- match the scene to the energy of the section (calmer scenes for quiet parts, the biggest scene for the loudest section)
- crossfade between scenes over about one second (30 frames) instead of cutting
Print the timeline as a table: start time, end time, scene name.
Render one test frame from the middle of every scene and one from the middle of every crossfade, and show them to me as a contact sheet.
```

---

## Step 5: One finishing pass for every frame

A shared finishing pass makes separate scenes feel like one video.

```
Add a single post-processing function that every frame goes through after its scene draws it:
- a soft glow on the brightest parts (a blurred copy of the highlights, added back gently)
- a slight vignette that darkens the corners
- a guard against blowing out: no large area should hit pure white; compress the brightest values instead of clipping them
Keep it subtle. Re-render the same contact sheet from step 4 with the finishing pass on, and show me before and after side by side.
```

---

## Step 6: Render, add the sound, and check thirty frames

```
Write a render script that:
1. draws every frame of the song through the timeline and the finishing pass, at 1920x1080 and 30 fps, and pipes the frames straight into ffmpeg (no need to save each PNG)
2. encodes the video as H.264 MP4 with a quality setting suitable for YouTube
3. adds my original song as the audio track with ffmpeg, so sound and picture line up exactly
4. prints progress and an estimate of the time remaining
Run it. When it finishes, pull 30 frames spread evenly across the finished video, plus one frame from the middle of every crossfade, and show them to me as a contact sheet with the time under each one.
```

Watch the whole video once with sound before you share it. Then go through the checklist below.

---

## Check your frames

Look at the contact sheet from step 6 and at the video itself. Fix anything that fails before you post.

- [ ] **Things are what they claim to be.** If a scene shows a guitar, it has six strings, frets and tuning pegs. If it shows a hand, count the fingers. If it shows a moon, it is round.
- [ ] **Nothing is clipped or garbled.** No shapes cut off at the frame edge by accident, no broken lines, no stray pixels in a corner.
- [ ] **Text is readable.** Any title or lyric is large enough on a phone, has enough contrast, and is spelled right.
- [ ] **No pure white blowouts.** Bright moments glow; they do not turn into flat white blocks.
- [ ] **No scene sits still while the music moves.** Scrub to the busiest part of each scene. Something should be clearly reacting.
- [ ] **Transitions are clean.** Every crossfade blends two scenes. None of them flash black or white unless you meant it.
- [ ] **Sound and picture line up.** Beats in the picture land on beats in the audio from the first second to the last.

---

## Honest limits

- **Rendering is slow.** Drawing every frame in Python takes time. A six to seven minute song can take most of an hour on a small machine, and longer with heavy effects. Test with stills and short clips; render the full song once you are happy.
- **You cannot perfectly split a finished song into instruments.** Bass, mids and highs are a good stand-in, and stem-separation tools can help, but on a mixed-down recording any "this shape follows the drums" visual will be approximate. Plan scenes that look good even when the split is not clean.
- **Only use music you have the rights to.** Your own songs, music you have licensed, or music whose licence allows this kind of use. A video made in code is still a copy of the song.
- **Your assistant can be wrong.** It may say a frame looks good when it does not. Look at the pictures yourself; that is what steps 3 and 6 are for.

---

## Licence

Free to use, change and share under the Known Quantity LLC plain-language licence: knownquantityllc.com/templates/LICENSE.txt. Provided as is, with no warranty.

Made by Known Quantity LLC. If this helped you make something, pass it on to someone else who might like it.
