Skip to content

Instantly share code, notes, and snippets.

@LukasKnuth
Created December 6, 2019 21:47
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LukasKnuth/4d7ee6812ccb221b2775e984516b56d4 to your computer and use it in GitHub Desktop.
Save LukasKnuth/4d7ee6812ccb221b2775e984516b56d4 to your computer and use it in GitHub Desktop.
ffmpeg Merge two Audio Streams into one

This script takes a single input file and

  1. Reduces the volume of the third audio-track in the file by half
  2. Writes the reduced volume track into l
  3. Mixes both the second audio-track and the lowered l-track together and stores them into a
  4. Maps the original video to be the first track
  5. Adds the newly mixed audio-track a as the sole audio track
  6. Enables pass-through for the video-track
  7. Configures the mixed audio-track to be AAC at 192kbit/s

Selector

[0:a:2] selects from the first file (0) the audio track (a) at 0-based index 2 (2)

Filter I/O

Filters are composed by input (left side), the filter-name, options and the output: [0:a:1] [l] amix=inputs=2 [a]

  • Input 1: From the first input-file use the audio track and index 1
  • Input 2: Use the previously created track l
  • Filter Name: amix
  • Options: inputs=2 sets input-count to two. (multiple options seperated by :)
  • Output: a the new audio-track

Documentation

ffmpeg -y \
-i "input.mkv" \
-filter_complex "[0:a:2] volume=0.5 [l] ; [0:a:1] [l] amix=inputs=2 [a]" \
-map "0:v:0" \
-map "[a]" \
-c:v copy \
-c:a aac \
-b:a 192k \
"output.mkv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment