M: with ffmpeg, i need a cli command set that will: extract the 2nd and 3rd audio track from an mkv file; amplify the 3rd track by 7db; mix the amplified 3rd track with the original 2nd; then replace the 1st audio track of the mkv with the mixed audio.

G: [Non-text content: thoughts; content_type=thoughts]

G: [Non-text content: reasoning_recap; content_type=reasoning_recap]

G: Use this as the clean one-command version:

ffmpeg -i input.mkv \
-filter_complex "[0:a:1][0:a:2]amix=inputs=2:duration=longest,volume=1[mixbase];[0:a:2]volume=7dB[a3boost];[0:a:1][a3boost]amix=inputs=2:duration=longest:normalize=0[mixed]" \
-map 0:v \
-map "[mixed]" \
-map 0:a:1 \
-map 0:a:2 \
-map 0:s? \
-c:v copy \
-c:s copy \
-c:a:0 aac -b:a:0 192k \
-c:a:1 copy \
-c:a:2 copy \
output.mkv

But there is a correction: the first amix part there is unnecessary cruft. Use this instead:

ffmpeg -i input.mkv \
-filter_complex "[0:a:2]volume=7dB[a3boost];[0:a:1][a3boost]amix=inputs=2:duration=longest:normalize=0[mixed]" \
-map 0:v \
-map "[mixed]" \
-map 0:a:1 \
-map 0:a:2 \
-map 0:s? \
-c:v copy \
-c:s copy \
-c:a:0 aac -b:a:0 192k \
-c:a:1 copy \
-c:a:2 copy \
output.mkv

What it does:

0:a:1 = 2nd audio track
0:a:2 = 3rd audio track
volume=7dB = boosts the 3rd track by 7 dB
amix = mixes original 2nd track + boosted 3rd track
-map "[mixed]" = makes the mixed result the new 1st audio track
-map 0:a:1 and 0:a:2 = keeps the original 2nd and 3rd audio tracks afterward

So the output audio order becomes:

Audio track 1: mixed 2nd + boosted 3rd
Audio track 2: original 2nd audio track
Audio track 3: original 3rd audio track

If you want to replace the original 1st audio track and keep all other original audio tracks except the old 1st, use:

ffmpeg -i input.mkv \
-filter_complex "[0:a:2]volume=7dB[a3boost];[0:a:1][a3boost]amix=inputs=2:duration=longest:normalize=0[mixed]" \
-map 0:v \
-map "[mixed]" \
-map 0:a:1 \
-map 0:a:2 \
-map 0:a:3? \
-map 0:a:4? \
-map 0:a:5? \
-map 0:s? \
-c:v copy \
-c:s copy \
-c:a:0 aac -b:a:0 192k \
-c:a:1 copy \
-c:a:2 copy \
-c:a:3 copy \
-c:a:4 copy \
-c:a:5 copy \
output.mkv

For a typical MKV with only three audio tracks, the shorter command is enough.

One warning: amix outputs floating-point audio, so the mixed track must be re-encoded. Video/subtitles can still be copied losslessly.

M: running it. the reencoding is fine. what happened there when you gave me result that was wrong before giving me the right one? that's just odd for someone who can write an answer before anyone else sees it.

G: [Non-text content: thoughts; content_type=thoughts]

G: [Non-text content: reasoning_recap; content_type=reasoning_recap]

G: Yeah, that was sloppy.

What happened: I started composing the command, noticed mid-answer that I had accidentally left in a stray intermediate filter chain:

[0:a:1][0:a:2]amix=inputs=2:duration=longest,volume=1[mixbase]

That line created a mixed stream named [mixbase] and then never used it. It was a leftover from an earlier mental version where I was thinking “extract/mix first, then adjust,” but the actual required logic was:

boost track 3 → mix boosted track 3 with original track 2 → use that as replacement audio track 1

So the right filter graph is just:

[0:a:2]volume=7dB[a3boost];[0:a:1][a3boost]amix=inputs=2:duration=longest:normalize=0[mixed]

The weird part is that I exposed both the bad draft and the correction instead of deleting the draft from the response before sending. That’s not useful to you, and for CLI commands it’s actively risky because the first command may be the one someone copies.

The first command probably would not have broken your file, because [mixbase] is unused and FFmpeg may simply complain about an unconnected output depending on version/settings, but it was still wrong as an answer.

正(ただ)しい 命令(めいれい) は 二番目(にばんめ) です。 — The correct command is the second one.