[FFmpeg-user] Downmixing an audio stream while keeping a copy of the original stream

Kieran O Leary kieran.o.leary at gmail.com
Sat Dec 23 17:20:50 EET 2017


On Sat, Dec 23, 2017 at 1:01 PM, Adam Baxter <voltagex at voltagex.org> wrote:
> On 23 December 2017 at 21:24, Kieran O Leary <kieran.o.leary at gmail.com>
> wrote:
>>  ffmpeg -i "out.mkv" -map 0:v -c:v copy -c:a:0 aac -b:a:0 192k -ac:a:0
>> 2 -filter_complex
>> "[a:0]pan=stereo|FL=FC+0.30*FL+0.30*BL|FR=FC+0.30*FR+0.30*BR[a]" -map
>> [a] -map a:0:1 -c:a:1 copy "output.mkv"
> I think our command lines now match up: ffmpeg -i "input.mkv" -map 0:v -c:v copy
> -c:a:1 copy

Why did you add in this command when it's repeated at the end of the
command? Do you see any difference when removing it or keeping it?

> -c:a:0 aac -b:a:0 192k -ac:a:0 2 -filter_complex
> "[a:0]pan=stereo|FL=FC+0.30*FL+0.30*BL|FR=FC+0.30*FR+0.30*BR[a]" -map [a]
> -map a:0:1 -c:a:1 copy "output.mkv"
> This works perfectly, but I really don't understand how! I especially don't
> understand the [a] at the end of the filter. I'll try to clean up the
> command line a bit tomorrow to make some sense of it.

I don't 100% understand it either, but the answer would be in here:
http://ffmpeg.org/ffmpeg-filters.html and

>From what I understand, you had some redundancy in your original command:

> ffmpeg -i "input.mkv" -map 0:v -c:v copy -map 0:a

This all looks OK, you are mapping all audio and video input streams
and specifying that you want to copy the video.

> -c:a:1 copy
this seems to just get ignored by ffmpeg as it might get overridden by
the -filter_complex call later on in your command.

>-map 0:a -c:a:0 aac -b:a:0 192k -ac:a:0 2
I think this would have worked fine if you didn't have the
filter_complex call. You can do things like
` ffmpeg -i input.mkv -map 0:a -c:a:0 libmp3lame -map 0:a -c:a:1 aac
-map 0:a -c:a:2 pcm_s16le loadsofaudio.mkv`

and you'll get an mkv where you'll have three audio streams (aac, mp3,
pcm) in your mkv.

> -filter_complex "[a:0]pan=stereo|FL=FC+0.30*FL+0.30*BL|FR=FC+0.30*FR+0.30*BR"
> -c:a:1 copy

You've declared this `-c:a:1 copy` twice in your command and it looks
like it gets ignored each time, most likely as your filtergraph
overrides this (i'm not sure if this is the case).

So in my command:

 ffmpeg -i "out.mkv" -map 0:v -c:v copy -c:a:0 aac -b:a:0 192k -ac:a:0
2 -filter_complex
"[a:0]pan=stereo|FL=FC+0.30*FL+0.30*BL|FR=FC+0.30*FR+0.30*BR[a]" -map
^^ All the audio commands at this point are just relating to the audio
produced by the pan complex filter. the [a] is just a variable
arbitrary label that is used to refer to the stream that is outputted
from the filter. You can call it anything you want, as long as you
refer to it when you map it (-map [a]).

 -map a:0:1 -c:a:1 copy
^^ So now these commands allow you to start afresh from what I can
see, as you are processing the source audio stream, not the output of
the filtergraph.

Hopefully that helps somewhat.



More information about the ffmpeg-user mailing list