[FFmpeg-devel] [PATCH] lavfi/avfiltergraph: fix channel substitution score.

Nicolas George george at nsup.org
Sun Dec 7 13:31:59 CET 2014


Only count the number of channels that are present on input.
Fix a case where input FL+FR+BL gives a better score to 6.1
than quad because BL+BR→SL+SR counts as two remapped channels
while BL→BL+BR counts as one preserved and one extra.

Signed-off-by: Nicolas George <george at nsup.org>
---
 libavfilter/avfiltergraph.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


There are more issues in this score logic.
For example stereo+BR→stereo+SL is accepted because of the BL+BR→SL+SR
substitution, this is wrong.

The obvious fix would be to change "(out_chlayout & cmp1)" into
"(out_chlayout & cmp1) == cmp1", i.e. only accept a substitution if the
target is entirely available in the output, but that would break the case
stereo+BR→stereo+SL.

I do not have time for a more complete fix right now, but I believe the
present patch is valid and useful by itself.


diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index a859ecb..7d358a4 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -923,13 +923,14 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter)
             for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
                 uint64_t cmp0 = ch_subst[k][0];
                 uint64_t cmp1 = ch_subst[k][1];
+                uint64_t mapped = in_chlayout & cmp0;
                 if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
                     (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
                     in_chlayout  &= ~cmp0;
                     out_chlayout &= ~cmp1;
                     /* add score for channel match, minus a deduction for
                        having to do the substitution */
-                    score += 10 * av_get_channel_layout_nb_channels(cmp1) - 2;
+                    score += 10 * av_get_channel_layout_nb_channels(mapped) - 2;
                 }
             }
 
-- 
2.1.3



More information about the ffmpeg-devel mailing list