Multiple audio encodings out from the same stream

Useful and helpful Windows specific command line samples and examples.
Post Reply
Posts: 1
Joined: Mon Aug 15, 2016 1:02 pm

Multiple audio encodings out from the same stream

Post by jgauthier72 »

Hi all,

I am a newbie with FFmpeg and there is a scenario that I am trying to make work with no success.

I'd like to take a source MKV file which has a H.264 video stream and multiple AC3 audio streams and create an output file which is exactly the same with the difference that I want it to have 2 additional audio streams with different bit rates (or format), encoded out of the same source stream. Is that possible to do with a single input (-i) file? The way I understand it, if i use specifiers like "-c copy" followed by "-c:a:5 aac", FFmpeg applies the "all with the exception of" logic and therefore, the result is not an additional stream but a converted one that replaces the original.

I've tried using 2 input files (with the same file name) to do that but although the ouput mapping seems to work, I keep getting "Starting new cluster due to timestamp" warnings during the processing and it fails before the end.

thanks for your help

Posts: 1882
Joined: Fri Aug 05, 2011 9:56 pm

Re: Multiple audio encodings out from the same stream

Post by rogerdpack »

I believe it should be possible, but don't know precisely and can only point you to this:


Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: Multiple audio encodings out from the same stream

Post by pandy »

Code: Select all

@ffmpeg.exe -i "%1" -map 0:v -c:v libx264 -map 0:a -c:a:0 ac3 -b:a:0 384k -filter_complex [0:a:0]anull[a2c] -map [a2c]:1 -c:a:1 libmp3lame -q:a:1 6 -f matroska "%~n1.mkv"
Above will add audio with different codec than source (so first audio track is transcoded to AC3, first audio track is mapped to filter complex and processed - i've stripped out my processing to simplify example - replaced by anull which copy audio unchanged, output from filter complex is mapped as additional audio track).
Use this as example, ffmpeg is very sensitive for proper mapping (which itself is not so clear as sometimes 0 is 1 and 1 can be 2 etc). After few tries i think it will be easier - for me is usually some exercise to make it work with different source structure .

Posts: 2
Joined: Thu May 03, 2018 7:48 pm

Re: Multiple audio encodings out from the same stream

Post by RayMpeg4 »

It is child's play to use MKVToolnix to mux in 2 additional audio streams of any format. However, this can't be automated, as with using an FFmpeg script. for Windows.

Tip: In Pandy's script the [ "%1" ] must be changed to either [ %1 ] or [ "%~F1" ] to prevent two sets of double-quotes from surrounding any input file path that has embedded spaces in it. The parameter [ %1 ] will automatically provide its own surrounding double-quotes whenever it's necessary (and none when not needed). [ "%~F1" ] never expands to having surrounding double-quotes, but it won't hurt always adding them in any CMD, BAT or PS1 script whether or not the filepath has any embedded spaces anywhere in it.

Post Reply