[Libav-user] Channel mapping with amerge filter

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] Channel mapping with amerge filter

Kerry Loux
Hello all,

I'm trying to create an audio filter graph (in C/C++) that takes a number of inputs and mixes/splits/merges as necessary to produce a single stream with multiple channels.

I would like to be able to control which amerge input is mapped to which channel in the output stream. For example, if I'm merging two inputs, I want to control which is the left and which is the right channel. Similarly, for cases with more than two inputs, I'd like to know/control which output layout is being created and how each input is mapped.

Currently, I have an implementation that generates a stream with the correct individual channels, but mapped incorrectly. When I call av_filter_graph_config(), I get a message stating "Input channel layouts overlap; output layout will be determined by the number of distinct input channels," which seems like a clue.

When I checked the source in af_amerge.c, I see that there is a route[] array which I presume controls this mapping. Is this correct?

If so, then how should I access this array? Through context->priv directly?

Is there a way to define the output layout for the output of the amerge filter?

Thanks in advance,

Kerry

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Channel mapping with amerge filter

Paul B Mahol
On 5/28/20, Kerry Loux <[hidden email]> wrote:

> Hello all,
>
> I'm trying to create an audio filter graph (in C/C++) that takes a number
> of inputs and mixes/splits/merges as necessary to produce a single stream
> with multiple channels.
>
> I would like to be able to control which amerge input is mapped to which
> channel in the output stream. For example, if I'm merging two inputs, I
> want to control which is the left and which is the right channel.
> Similarly, for cases with more than two inputs, I'd like to know/control
> which output layout is being created and how each input is mapped.
>
> Currently, I have an implementation that generates a stream with the
> correct individual channels, but mapped incorrectly. When I call
> av_filter_graph_config(), I get a message stating "Input channel layouts
> overlap; output layout will be determined by the number of distinct input
> channels," which seems like a clue.
>
> When I checked the source in af_amerge.c, I see that there is a route[]
> array which I presume controls this mapping. Is this correct?
>
> If so, then how should I access this array? Through context->priv directly?
>
> Is there a way to define the output layout for the output of the amerge
> filter?

Not possible at all, use join filter instead.
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Channel mapping with amerge filter

Nicolas George
In reply to this post by Kerry Loux
Kerry Loux (12020-05-28):

> I'm trying to create an audio filter graph (in C/C++) that takes a number
> of inputs and mixes/splits/merges as necessary to produce a single stream
> with multiple channels.
>
> I would like to be able to control which amerge input is mapped to which
> channel in the output stream. For example, if I'm merging two inputs, I
> want to control which is the left and which is the right channel.
> Similarly, for cases with more than two inputs, I'd like to know/control
> which output layout is being created and how each input is mapped.
>
> Currently, I have an implementation that generates a stream with the
> correct individual channels, but mapped incorrectly. When I call
> av_filter_graph_config(), I get a message stating "Input channel layouts
> overlap; output layout will be determined by the number of distinct input
> channels," which seems like a clue.
Ignore the reply that tells you it is not possible, it is wrong and
unfounded.

To make this work, you need to understand what channels layout are. If
you do not already, read the doc before trying further.

amerge has two modes of operation, depending on the channel layout of
its inputs.

If the inputs have channel layouts with completely different channels
(for example FL+FR+BL+BR on one input and FC+LF on the other), then the
output will be made of these combined channels. The channels will be
reordered to match the standard channel order of FFmpeg (with the given
example: FL+FR+FC+LF+BL+BR: notice that the two channels of the second
inputs were inserted between the channels of the first input).

If the inputs have channel layouts with the same channel in both (for
example FL+FR+FC merged with FL+FR+BL+BR), this cannot work, and amerge
falls back to ignoring the channel layout. In that case, amerge will
output all the channels in order: first the channels from the first
input, then the channels of the second input (in the example:
FL1+FR1+FC1+FL2+FR2+BL2+BR2).

Of course, the same happens if one of the inputs has no specified
channel layout.

It may happen that a latter filter will slap a channel layout on the
result. That channel layout would be random and irrelevant.

Hope this helped.

Regards,

--
  Nicolas George

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Channel mapping with amerge filter

Paul B Mahol
On 5/29/20, Nicolas George <[hidden email]> wrote:

> Kerry Loux (12020-05-28):
>> I'm trying to create an audio filter graph (in C/C++) that takes a number
>> of inputs and mixes/splits/merges as necessary to produce a single stream
>> with multiple channels.
>>
>> I would like to be able to control which amerge input is mapped to which
>> channel in the output stream. For example, if I'm merging two inputs, I
>> want to control which is the left and which is the right channel.
>> Similarly, for cases with more than two inputs, I'd like to know/control
>> which output layout is being created and how each input is mapped.
>>
>> Currently, I have an implementation that generates a stream with the
>> correct individual channels, but mapped incorrectly. When I call
>> av_filter_graph_config(), I get a message stating "Input channel layouts
>> overlap; output layout will be determined by the number of distinct input
>> channels," which seems like a clue.
>
> Ignore the reply that tells you it is not possible, it is wrong and
> unfounded.
>

Your explanation bellow proves otherwise.

amerge filter is of very limited functionality and should be
deprecated and ultimately removed.

> To make this work, you need to understand what channels layout are. If
> you do not already, read the doc before trying further.
>
> amerge has two modes of operation, depending on the channel layout of
> its inputs.
>
> If the inputs have channel layouts with completely different channels
> (for example FL+FR+BL+BR on one input and FC+LF on the other), then the
> output will be made of these combined channels. The channels will be
> reordered to match the standard channel order of FFmpeg (with the given
> example: FL+FR+FC+LF+BL+BR: notice that the two channels of the second
> inputs were inserted between the channels of the first input).
>
> If the inputs have channel layouts with the same channel in both (for
> example FL+FR+FC merged with FL+FR+BL+BR), this cannot work, and amerge
> falls back to ignoring the channel layout. In that case, amerge will
> output all the channels in order: first the channels from the first
> input, then the channels of the second input (in the example:
> FL1+FR1+FC1+FL2+FR2+BL2+BR2).
>
> Of course, the same happens if one of the inputs has no specified
> channel layout.
>
> It may happen that a latter filter will slap a channel layout on the
> result. That channel layout would be random and irrelevant.
>
> Hope this helped.
>
> Regards,
>
> --
>   Nicolas George
>
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Channel mapping with amerge filter

Kerry Loux


On Fri, May 29, 2020, 7:04 AM Paul B Mahol <[hidden email]> wrote:
On 5/29/20, Nicolas George <[hidden email]> wrote:
> Kerry Loux (12020-05-28):
>> I'm trying to create an audio filter graph (in C/C++) that takes a number
>> of inputs and mixes/splits/merges as necessary to produce a single stream
>> with multiple channels.
>>
>> I would like to be able to control which amerge input is mapped to which
>> channel in the output stream. For example, if I'm merging two inputs, I
>> want to control which is the left and which is the right channel.
>> Similarly, for cases with more than two inputs, I'd like to know/control
>> which output layout is being created and how each input is mapped.
>>
>> Currently, I have an implementation that generates a stream with the
>> correct individual channels, but mapped incorrectly. When I call
>> av_filter_graph_config(), I get a message stating "Input channel layouts
>> overlap; output layout will be determined by the number of distinct input
>> channels," which seems like a clue.
>
> Ignore the reply that tells you it is not possible, it is wrong and
> unfounded.
>

Your explanation bellow proves otherwise.

amerge filter is of very limited functionality and should be
deprecated and ultimately removed.

> To make this work, you need to understand what channels layout are. If
> you do not already, read the doc before trying further.
>
> amerge has two modes of operation, depending on the channel layout of
> its inputs.
>
> If the inputs have channel layouts with completely different channels
> (for example FL+FR+BL+BR on one input and FC+LF on the other), then the
> output will be made of these combined channels. The channels will be
> reordered to match the standard channel order of FFmpeg (with the given
> example: FL+FR+FC+LF+BL+BR: notice that the two channels of the second
> inputs were inserted between the channels of the first input).
>
> If the inputs have channel layouts with the same channel in both (for
> example FL+FR+FC merged with FL+FR+BL+BR), this cannot work, and amerge
> falls back to ignoring the channel layout. In that case, amerge will
> output all the channels in order: first the channels from the first
> input, then the channels of the second input (in the example:
> FL1+FR1+FC1+FL2+FR2+BL2+BR2).
>
> Of course, the same happens if one of the inputs has no specified
> channel layout.
>
> It may happen that a latter filter will slap a channel layout on the
> result. That channel layout would be random and irrelevant.
>
> Hope this helped.
>
> Regards,
>
> --
>   Nicolas George
>
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

Thanks Nicholas. I was able to get it to work using the method you described.

Actually, I had tried it earlier, but I struggled  because I was passing invalid channel layouts to my src buffer filters. My mistake was that I expected av_get_channel_layout_string() to produce values suitable for passing as a "channel_layout" option to my buffer filters.

I may also consider Paul's suggestion to use a join filter instead, but I'm not sure that it will simplify anything for me since I'll likely still need splits and mixes for a general solution.

Thanks,

Kerry

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Channel mapping with amerge filter

Nicolas George
Kerry Loux (12020-05-29):
> Thanks Nicholas. I was able to get it to work using the method you
> described.

Good to ear.

> Actually, I had tried it earlier, but I struggled  because I was passing
> invalid channel layouts to my src buffer filters. My mistake was that I
> expected av_get_channel_layout_string() to produce values suitable for
> passing as a "channel_layout" option to my buffer filters.

That is worrying, I think they should be compatible. Do you remember
which particular channel layout caused a problem?

But you do not need it for this case, you can just print the channel
layout as an integer.

I forgot to add:

If you need to change the order of the channels afterwards, the filter
pan is there for that.

Regards,

--
  Nicolas George

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Channel mapping with amerge filter

Kerry Loux


On Fri, May 29, 2020, 1:46 PM Nicolas George <[hidden email]> wrote:
Kerry Loux (12020-05-29):
> Thanks Nicholas. I was able to get it to work using the method you
> described.

Good to ear.

> Actually, I had tried it earlier, but I struggled  because I was passing
> invalid channel layouts to my src buffer filters. My mistake was that I
> expected av_get_channel_layout_string() to produce values suitable for
> passing as a "channel_layout" option to my buffer filters.

That is worrying, I think they should be compatible. Do you remember
which particular channel layout caused a problem?

Yes, AV_CH_FRONT_LEFT is an example. The returned string is something like "1 channels (FL)." I had to extract only the parenthetical portion in order to avoid an "invalid argument" error when calling avfilter_init_str().


But you do not need it for this case, you can just print the channel
layout as an integer.

I forgot to add:

If you need to change the order of the channels afterwards, the filter
pan is there for that.

Regards,

--
  Nicolas George
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Channel mapping with amerge filter

Nicolas George
Kerry Loux (12020-05-29):
> Yes, AV_CH_FRONT_LEFT is an example. The returned string is something like
> "1 channels (FL)." I had to extract only the parenthetical portion in order
> to avoid an "invalid argument" error when calling avfilter_init_str().

Thanks. I just checked, and it is actually the expected behavior: the
output of av_get_channel_layout_string() is not meant to be used as
input later. The recommended way to encode a channel layout is to print
it as an integer. This is not very good design, but that is what we
have.

Regards,

--
  Nicolas George

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment