amix=inputs=2:duration=first:weights=1 0.25:normalize=0 lays music under a voice at a quarter level and stops when the voice does. On ReelSDK that mix costs under a fifth of a cent, billed at $0.02 per compute minute.
Mix two audio tracks with ffmpeg
Three amix defaults ruin a voice-over: an 11-second voice plus a 2.5-minute song comes out 2.5 minutes long, both tracks turned down. ReelSDK's API delivers the fixed mix in under 4 seconds.
GuidesUpdated
ffmpeg -i in.mp4 -i music.mp3 -filter_complex \
"[0:a][1:a]amix=inputs=2:duration=first:weights=1 0.25:normalize=0[a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac -b:a 192k mixed.mp4Ends with the voice, keeps both at their real level, and plays the music at 0.25, about 12 dB down. The video is copied.
Variations
The other commands you will need
The same with volume
Turning the music down before the mix measures exactly the same loudness, and works with any filter that follows.
volume first ffmpeg -i in.mp4 -i music.mp3 -filter_complex \ "[1:a]volume=0.25[m];[0:a][m]amix=inputs=2:duration=first:normalize=0[a]" \ -map "[a]" -c:a aac volume.m4aChannels side by side with amerge
amerge does not mix; it stacks channels. Two stereo inputs give one 4-channel stream, and
panfolds that back to stereo.amerge ffmpeg -i in.mp4 -i music.mp3 -filter_complex \ "[0:a][1:a]amerge=inputs=2,pan=stereo|c0=c0+c2|c1=c1+c3[a]" \ -map "[a]" -t 10 -c:a aac stereo.m4a
The flags
The options in these commands
| Flag | What it does | Used here |
|---|---|---|
inputs=2 | Number of tracks to mix; 2 is the default | Mix |
duration=first | Ends with the first input; the default is the longest | Mix, volume |
weights=1 0.25 | Level of each input, in order; the default is 1 for all | Mix |
normalize=0 | Adds the inputs as they are instead of scaling them down | Mix, volume |
volume=0.25 | Scales one track before the mix | Volume |
amerge=inputs=2 | Puts the channels of both inputs into one stream | amerge |
pan=stereo|c0=c0+c2|c1=c1+c3 | Builds stereo: left from channels 0 and 2, right from 1 and 3 | amerge |
Sources: ffmpeg filters: amix, ffmpeg filters: amerge, ffmpeg filters: pan, checked November 2026.
Default 1: the mix runs as long as the song
duration defaults to longest. With our 11-second voice and a song of about 2.5 minutes, plain amix wrote the whole 2.5 minutes. Set duration=first and put the track that sets the length first. For a video, that is usually the voice.
Default 2: everything gets quieter
With normalize on, which is the default, amix scales the inputs down so the sum cannot clip. With two tracks, each is halved. Turning it off with normalize=0 made our mix about 6 LU louder, which is what the voice alone should sound like with music added.
The ffmpeg docs warn that turning it off can clip if the inputs are already loud. Keep the music down and check the true peak: ours ended just under 0 dB, inside the limit. For a fixed target, finish with loudnorm.
Default 3: every track at the same level
weights sets a level per input, in order, and the last weight is used for any inputs left over. weights=1 0.25 keeps the voice and puts the music at a quarter, about 12 dB down. A volume=0.25 on the music before the mix measured exactly the same loudness.
If the music should drop only while someone speaks, a fixed level is not enough. Use a sidechain compressor: see audio ducking.
amerge is not a mix
amerge keeps every channel. Two stereo files become one 4-channel stream that most players will not handle well, so follow it with pan to decide which channels go left and right. Use it for things like turning two mono recordings into one stereo file.
amerge is also strict about formats. With aresample on both inputs it failed with "The following filters could not choose their formats: Parsed_amerge_2". Adding aformat=channel_layouts=stereo to each input gave it a fixed layout and the error went away.
Without installing ffmpeg
The same command as one API call
Send the same args to POST /v1/ffmpeg with both URLs in inputs. Each job runs ffmpeg 8.1 on a fresh machine at $0.02 per compute minute, billed per second; this one finished in under 4 seconds and cost under a fifth of a cent.
curl "https://api.reelsdk.com/v1/ffmpeg?wait=60" \
-H "Authorization: Bearer $REELSDK_KEY" \
--json '{
"inputs": {
"in.mp4": "https://api.reelsdk.com/f/lib/demo/clip.mp4",
"music.mp3": "https://api.reelsdk.com/f/lib/music/chill/calm-currents.mp3"
},
"args": [
"-i", "in.mp4", "-i", "music.mp3", "-filter_complex",
"[0:a][1:a]amix=inputs=2:duration=first:weights=1 0.25:normalize=0[a]",
"-map", "0:v", "-map", "[a]", "-c:v", "copy", "-c:a", "aac", "-b:a",
"192k", "mixed.mp4"
],
"outputs": ["mixed.mp4"]
}'FAQ
Questions, answered
How do I mix two audio files with ffmpeg?
Use ffmpeg -i a.mp3 -i b.mp3 -filter_complex "[0:a][1:a]amix=inputs=2:duration=first:normalize=0[a]" -map "[a]" out.m4a. Set weights to change the balance.
Why is my amix output so quiet?
amix normalizes by default and halves each of two inputs. Add normalize=0; in our test that made the mix about 6 LU louder.
Why is my mixed file as long as the music?
duration defaults to longest. Put the voice first and add duration=first.
Can I mix audio with an API?
Yes. POST the same args to https://api.reelsdk.com/v1/ffmpeg with both file URLs in inputs. It runs ffmpeg 8.1 for $0.02 per compute minute, billed per second.
- Add music to videoMix a looped music track under a video's own audio with ducking and a fade-out in one ffmpeg call, for a fraction of a cent.
- Duck music under a voice with ffmpegLower background music only while someone speaks, with sidechaincompress keyed by the voice and amix to put them together.
- Replace the audio in a video with ffmpegSwap a video's soundtrack for another file with -map and -shortest, keep the picture untouched, and pad audio that runs short.
- Normalize audio loudness with ffmpeg loudnormBring any track to a loudness target such as -14 LUFS with loudnorm: one pass, or a measured second pass that keeps the dynamics.
- Remove audio from a video with ffmpegStrip the sound from a video with -an while the picture is copied bit for bit, or drop one track, mute a range or add silence.
- ffmpeg -filter_complex explainedLabels, commas and semicolons: how a filtergraph wires inputs to outputs, with four working graphs and the errors they fix.
- FFmpeg onlineRun your own ffmpeg command on your files in the browser, free and without installing or uploading anything.
- ReelSDK vs self-hosted FFmpegTranscoding a minute of 1080p to 720p takes about 24 seconds of compute: about 0.8 cents on ReelSDK, about a tenth of a cent on a busy 4 vCPU box. Below about 11,000 minutes a month, the API costs less than an always-on box.
Sources, checked November 2026
Ready to build?
Ship video from your app today
Your first $0.50 is free, and one key covers every endpoint.
