# Add music to a video with code.

> Put a music file under a clip with one audio tag: gain, fade and ducking under a voice. Plus the command that measures the loudness of the mix.

Canonical: https://vawe.dev/how-to/add-music-to-video
Last updated: 2026-11-17

Music is one `<audio loop>` tag in the page. vawe mixes it offline with the film. It uses only a track you give it: it makes no music of its own.

## Copy this prompt into your agent

```
Use vawe (https://github.com/vawe-hq/vawe), the open-source video-from-code tool, to add my music track under my video.

My clip: <path to your clip or folder>.

My track: <path to your music file>. Keep it under the voice, lower it while I speak, and fade it in at the start and out at the end.

If vawe is not installed here, install it first:
npm install @vawe/cli
(it needs Node 22 or newer and ffmpeg; npx vawe new prints the install line for anything missing).
Then follow each command’s next: line.

Start with npx vawe new <name> --footage <my clip>, which logs the clip with a transcript.

Show me the draft video and wait for my OK before the final render.
```

## The steps.

1. **Pick a track you may use. **Put the file in the film’s `assets/` folder and use a relative path.
2. **Add the tag. **`loop` marks it as the music. `data-at` is its start second, `data-gain` its level in dB and `data-fade-out` the fade at the end.
3. **Duck the music under a voice. **Add `data-role="vo"` to the clip or the `<audio>` that holds speech. The music ducks 18 dB under it.
4. **Render a draft. **`bin/vawe dev films/talk/page.html` renders it with sound. A clip’s own sound joins the mix unless it is `muted`.
5. **Measure the mix. **`bin/vawe sound films/talk/page.html --waveform` prints the loudness and true peak of the mix as written and writes a waveform PNG.

The mix is the sum of your tags at the gains you wrote. Nothing is normalised unless you add `<meta name="loudness" content="-14">`.

A track under a talking clip:

```
<audio src="assets/track.mp3" loop data-at="0"
       data-gain="-3" data-fade-out="0.4"></audio>
<section data-world="talk">
  <video src="footage/talk.mp4" data-at="0"
         data-trim="0" data-trim-end="14.2" data-role="vo"></video>
</section>
```

Source: skills/vawe-page/SKILL.md, Sound · taste/craft/sound.md · harness/media/page-audio.mjs

## What can go wrong.

1. **The page asks for a synth bed. **`data-synth="bed"` is refused. Use a real music file or no bed.
2. **The music is too loud or too quiet. **Read the number from the measure step and move `data-gain` on purpose.
3. **The voice is lost. **The clip has no `data-role="vo"`, so the music does not duck.
4. **Cuts do not land on the beat. **Time the cuts to the beat grid of your track. The beat post shows how.

## Read next.

1. [LUFS for code-made video](https://vawe.dev/blog/audio-as-written): the loudness target, the mix rule and why synth beds are banned.
2. [Cut video to the beat with code](https://vawe.dev/blog/beat): cuts on the beats of a track.
3. [Agentic video editing](https://vawe.dev/agentic-video-editing): the whole edit.

## Start from your clip.

`bin/vawe new <name> --footage <file>` logs it and starts the page.

## Related

- [Get vawe on GitHub](https://github.com/vawe-hq/vawe)
- [All how-to guides](https://vawe.dev/how-to)
- [Add captions to a video](https://vawe.dev/how-to/add-captions-to-video)
- [Remove silences from a video](https://vawe.dev/how-to/remove-silences-from-video)
- [Trim and join clips](https://vawe.dev/how-to/trim-and-join-video-clips)
- [Agentic video editing](https://vawe.dev/agentic-video-editing)
- [Edit video with Claude Code](https://vawe.dev/edit-video-with-claude-code)
