Random Notes

Combining Audio Tracks in a Video With Ffmpeg

I use OBS Studio to store replays of my games with my friends for later. OBS writes two audio tracks to the file, one for game audio and one for my mic. I was surprised to find that multi-track files were not properly supported by many programs like Handbrake (or YouTube for that matter), so I needed to combine the audio tracks.

This is just a quick post to store the command I used to do that. This command merges the audio tracks in the input video, lowers the volume on the mic track (track 1), and copies the video data without re-encoding:

ffmpeg -i 'input.mkv' -filter_complex '[0:a:1]volume=0.1[l];[0:a:0][l]amerge=inputs=2[a]' -map '0:v:0' -map '[a]' -c:v copy -c:a libmp3lame -q:a 3 -ac 2 'output.mp4'

My understanding of the command is as follows:

I’m still a beginner in this, so if you do notice any errors, please comment. Documenting this is both a note for myself and hopefully may help others find this by googling (it was surprisingly difficult to find this combination).

Related Stack Overflow post: https://stackoverflow.com/questions/45824127/how-do-i-use-ffmpeg-to-merge-all-audio-streams-in-a-video-file-into-one-audio