ffmpeg – can one filter_complex handle different audio layouts?

I am trying to set up an ffmpeg command that handles 2 different audio layouts on the input:
type #1: a single stereo track, i.e. [0:a:0] is a stereo channel.
type #2: a couple of mono tracks, i.e. [0:a:0] and [0:a:1] are mono channels.

is there a way to tell ffmpeg with a single filtergraph to take whichever 2 audio tracks it identifies regardless of their layout and map them into the output’s stereo track?

the following filtergraph string does the right thing to the stereo input file (type #1) and throws no errors when a type #2 file is on the input, but in the case of type #2 only the left channel is there:

[0:a]pan=stereo|c0=c0|c1=c1[str_in];[str_in]amerge=inputs=1[aout]

in fact, when applied on a type #2 file there’s a warning saying:

Input channel layout has a different number of channels than the
number of used channels, ignoring layout

is there a way to handle those 2 input types in a single command?
the challenge here is not to use explicit input references such as [0:a:1]

Read more here: Source link