[FFmpeg-devel] [PATCH 274/279] avfilter: convert to new channel layout API

James Almer jamrial at gmail.com
Wed Dec 8 03:06:44 EET 2021


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavfilter/aeval.c                |  19 +-
 libavfilter/af_afir.c              |   9 +-
 libavfilter/af_aformat.c           |  32 +++-
 libavfilter/af_amerge.c            |  38 ++--
 libavfilter/af_amix.c              |   2 +-
 libavfilter/af_apulsator.c         |   2 +-
 libavfilter/af_aresample.c         |  41 +++--
 libavfilter/af_ashowinfo.c         |  13 +-
 libavfilter/af_asr.c               |   2 +-
 libavfilter/af_biquads.c           |  42 ++---
 libavfilter/af_bs2b.c              |   2 +-
 libavfilter/af_channelmap.c        |  86 +++++----
 libavfilter/af_channelsplit.c      |  42 +++--
 libavfilter/af_compand.c           |   6 +
 libavfilter/af_compensationdelay.c |   7 +
 libavfilter/af_crossfeed.c         |   2 +-
 libavfilter/af_earwax.c            |   2 +-
 libavfilter/af_extrastereo.c       |   2 +-
 libavfilter/af_firequalizer.c      |   5 +-
 libavfilter/af_haas.c              |   2 +-
 libavfilter/af_hdcd.c              |   4 +-
 libavfilter/af_headphone.c         |  22 +--
 libavfilter/af_join.c              | 268 +++++++++++++++++++----------
 libavfilter/af_ladspa.c            |  16 +-
 libavfilter/af_lv2.c               |  17 +-
 libavfilter/af_pan.c               |  62 +++----
 libavfilter/af_replaygain.c        |   2 +-
 libavfilter/af_sofalizer.c         |  86 ++++-----
 libavfilter/af_speechnorm.c        |  12 +-
 libavfilter/af_stereotools.c       |   2 +-
 libavfilter/af_stereowiden.c       |   2 +-
 libavfilter/af_surround.c          |  72 ++++----
 libavfilter/asrc_afirsrc.c         |   2 +-
 libavfilter/asrc_anoisesrc.c       |   2 +-
 libavfilter/asrc_anullsrc.c        |  13 +-
 libavfilter/asrc_flite.c           |   6 +-
 libavfilter/asrc_hilbert.c         |   2 +-
 libavfilter/asrc_sinc.c            |   2 +-
 libavfilter/asrc_sine.c            |   2 +-
 libavfilter/audio.c                |  11 +-
 libavfilter/avf_aphasemeter.c      |   2 +-
 libavfilter/avf_avectorscope.c     |   2 +-
 libavfilter/avf_showcqt.c          |   3 +-
 libavfilter/avf_showspatial.c      |   2 +-
 libavfilter/avf_showspectrum.c     |   3 +-
 libavfilter/avf_showvolume.c       |   9 +-
 libavfilter/avfilter.c             |  15 +-
 libavfilter/avfilter.h             |  10 +-
 libavfilter/avfiltergraph.c        |  84 +++++----
 libavfilter/buffersink.c           |  29 +++-
 libavfilter/buffersink.h           |   7 +-
 libavfilter/buffersrc.c            |  92 +++++++---
 libavfilter/buffersrc.h            |   9 +
 libavfilter/f_ebur128.c            |  10 +-
 libavfilter/f_streamselect.c       |   4 +
 libavfilter/formats.c              | 131 +++++++++-----
 libavfilter/formats.h              |  16 +-
 libavfilter/graphdump.c            |   4 +-
 libavfilter/internal.h             |   2 +-
 libavfilter/src_movie.c            |  19 +-
 libavfilter/tests/filtfmts.c       |   3 +-
 libavfilter/tests/formats.c        |   8 +-
 libavfilter/vaf_spectrumsynth.c    |   2 +-
 tests/ref/fate/filter-formats      |  20 +--
 64 files changed, 903 insertions(+), 544 deletions(-)

diff --git a/libavfilter/aeval.c b/libavfilter/aeval.c
index 42cfa81325..58db12c026 100644
--- a/libavfilter/aeval.c
+++ b/libavfilter/aeval.c
@@ -57,7 +57,7 @@ typedef struct EvalContext {
     const AVClass *class;
     char *sample_rate_str;
     int sample_rate;
-    int64_t chlayout;
+    AVChannelLayout chlayout;
     char *chlayout_str;
     int nb_channels;            ///< number of output channels
     int nb_in_channels;         ///< number of input channels
@@ -70,7 +70,6 @@ typedef struct EvalContext {
     uint64_t n;
     double var_values[VAR_VARS_NB];
     double *channel_values;
-    int64_t out_channel_layout;
 } EvalContext;
 
 static double val(void *priv, double ch)
@@ -181,7 +180,7 @@ static av_cold int init(AVFilterContext *ctx)
             if (ret < 0)
                 return ret;
 
-            ret = parse_channel_expressions(ctx, av_get_channel_layout_nb_channels(eval->chlayout));
+            ret = parse_channel_expressions(ctx, eval->chlayout.nb_channels);
             if (ret < 0)
                 return ret;
         }
@@ -190,8 +189,8 @@ static av_cold int init(AVFilterContext *ctx)
         if ((ret = parse_channel_expressions(ctx, -1)) < 0)
             return ret;
 
-        eval->chlayout = av_get_default_channel_layout(eval->nb_channels);
-        if (!eval->chlayout && eval->nb_channels <= 0) {
+        av_channel_layout_default(&eval->chlayout, eval->nb_channels);
+        if (eval->nb_channels <= 0) {
             av_log(ctx, AV_LOG_ERROR, "Invalid number of channels '%d' provided\n",
                    eval->nb_channels);
             return AVERROR(EINVAL);
@@ -231,7 +230,7 @@ static int config_props(AVFilterLink *outlink)
     eval->var_values[VAR_NB_IN_CHANNELS] = NAN;
     eval->var_values[VAR_NB_OUT_CHANNELS] = outlink->channels;
 
-    av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout);
+    av_channel_layout_describe(&eval->chlayout, buf, sizeof(buf));
 
     av_log(outlink->src, AV_LOG_VERBOSE,
            "sample_rate:%d chlayout:%s duration:%"PRId64"\n",
@@ -244,7 +243,7 @@ static int query_formats(AVFilterContext *ctx)
 {
     EvalContext *eval = ctx->priv;
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE };
-    int64_t chlayouts[] = { eval->chlayout ? eval->chlayout : FF_COUNT2LAYOUT(eval->nb_channels) , -1 };
+    AVChannelLayout chlayouts[] = { eval->chlayout.nb_channels ? eval->chlayout : FF_COUNT2LAYOUT(eval->nb_channels), { 0 } };
     int sample_rates[] = { eval->sample_rate, -1 };
     int ret;
 
@@ -365,9 +364,7 @@ static int aeval_query_formats(AVFilterContext *ctx)
     } else {
         // outlink supports only requested output channel layout
         layouts = NULL;
-        if ((ret = ff_add_channel_layout(&layouts,
-                              eval->out_channel_layout ? eval->out_channel_layout :
-                              FF_COUNT2LAYOUT(eval->nb_channels))) < 0)
+        if ((ret = ff_add_channel_layout(&layouts, &FF_COUNT2LAYOUT(eval->nb_channels))) < 0)
             return ret;
         if ((ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts)) < 0)
             return ret;
@@ -387,7 +384,7 @@ static int aeval_config_output(AVFilterLink *outlink)
     int ret;
 
     if (eval->same_chlayout) {
-        eval->chlayout = inlink->channel_layout;
+        eval->chlayout = inlink->ch_layout;
 
         if ((ret = parse_channel_expressions(ctx, inlink->channels)) < 0)
             return ret;
diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index ace5087e90..b1517af245 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -745,7 +745,7 @@ static int query_formats(AVFilterContext *ctx)
         if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
             return ret;
 
-        ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO);
+        ret = ff_add_channel_layout(&mono, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO);
         if (ret)
             return ret;
         for (int i = 1; i < ctx->nb_inputs; i++) {
@@ -764,11 +764,18 @@ static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     AudioFIRContext *s = ctx->priv;
+    int ret;
 
     s->one2many = ctx->inputs[1 + s->selir]->channels == 1;
     outlink->sample_rate = ctx->inputs[0]->sample_rate;
     outlink->time_base   = ctx->inputs[0]->time_base;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     outlink->channel_layout = ctx->inputs[0]->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&outlink->ch_layout, &ctx->inputs[0]->ch_layout)) < 0)
+        return ret;
     outlink->channels = ctx->inputs[0]->channels;
 
     s->nb_channels = outlink->channels;
diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
index ed3c75311a..f42e240cbd 100644
--- a/libavfilter/af_aformat.c
+++ b/libavfilter/af_aformat.c
@@ -104,9 +104,35 @@ static av_cold int init(AVFilterContext *ctx)
                   ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format");
     PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format,
                   get_sample_rate, 0, "sample rate");
-    PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts,
-                  ff_add_channel_layout, av_get_channel_layout, 0,
-                  "channel layout");
+    {
+        char *next, *cur = s->channel_layouts_str, sep;
+        int ret;
+
+        if (s->channel_layouts_str && strchr(s->channel_layouts_str, ',')) {
+            av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "
+                   "separate channel layouts.\n");
+            sep = ',';
+        } else
+            sep = '|';
+
+        while (cur) {
+            AVChannelLayout fmt = { 0 };
+            next = strchr(cur, sep);
+            if (next)
+                *next++ = 0;
+
+            ret = av_channel_layout_from_string(&fmt, cur);
+            if (ret < 0) {
+                av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur);
+                return ret;
+            }
+            if ((ret = ff_add_channel_layout(&s->channel_layouts, &fmt)) < 0) {
+                return ret;
+            }
+
+            cur = next;
+        }
+    }
 
     return 0;
 }
diff --git a/libavfilter/af_amerge.c b/libavfilter/af_amerge.c
index 9109af22c5..edc7933ab6 100644
--- a/libavfilter/af_amerge.c
+++ b/libavfilter/af_amerge.c
@@ -73,7 +73,8 @@ static int query_formats(AVFilterContext *ctx)
         AV_SAMPLE_FMT_NONE
     };
     AMergeContext *s = ctx->priv;
-    int64_t inlayout[SWR_CH_MAX], outlayout = 0;
+    AVChannelLayout *inlayout[SWR_CH_MAX] = { NULL }, outlayout = { 0 };
+    uint64_t outmask = 0;
     AVFilterChannelLayouts *layouts;
     int i, ret, overlap = 0, nb_ch = 0;
 
@@ -84,20 +85,21 @@ static int query_formats(AVFilterContext *ctx)
                    "No channel layout for input %d\n", i + 1);
             return AVERROR(EAGAIN);
         }
-        inlayout[i] = ctx->inputs[i]->incfg.channel_layouts->channel_layouts[0];
+        inlayout[i] = &ctx->inputs[i]->incfg.channel_layouts->channel_layouts[0];
         if (ctx->inputs[i]->incfg.channel_layouts->nb_channel_layouts > 1) {
             char buf[256];
-            av_get_channel_layout_string(buf, sizeof(buf), 0, inlayout[i]);
+            av_channel_layout_describe(inlayout[i], buf, sizeof(buf));
             av_log(ctx, AV_LOG_INFO, "Using \"%s\" for input %d\n", buf, i + 1);
         }
         s->in[i].nb_ch = FF_LAYOUT2COUNT(inlayout[i]);
         if (s->in[i].nb_ch) {
             overlap++;
         } else {
-            s->in[i].nb_ch = av_get_channel_layout_nb_channels(inlayout[i]);
-            if (outlayout & inlayout[i])
+            s->in[i].nb_ch = inlayout[i]->nb_channels;
+            if (av_channel_layout_subset(inlayout[i], outmask))
                 overlap++;
-            outlayout |= inlayout[i];
+            outmask |= inlayout[i]->order == AV_CHANNEL_ORDER_NATIVE ?
+                       inlayout[i]->u.mask : 0;
         }
         nb_ch += s->in[i].nb_ch;
     }
@@ -111,19 +113,20 @@ static int query_formats(AVFilterContext *ctx)
                "output layout will be determined by the number of distinct input channels\n");
         for (i = 0; i < nb_ch; i++)
             s->route[i] = i;
-        outlayout = av_get_default_channel_layout(nb_ch);
-        if (!outlayout && nb_ch)
-            outlayout = 0xFFFFFFFFFFFFFFFFULL >> (64 - nb_ch);
+        av_channel_layout_default(&outlayout, nb_ch);
+        if (!KNOWN(&outlayout) && nb_ch)
+            av_channel_layout_from_mask(&outlayout, 0xFFFFFFFFFFFFFFFFULL >> (64 - nb_ch));
     } else {
         int *route[SWR_CH_MAX];
         int c, out_ch_number = 0;
 
+        av_channel_layout_from_mask(&outlayout, outmask);
         route[0] = s->route;
         for (i = 1; i < s->nb_inputs; i++)
             route[i] = route[i - 1] + s->in[i - 1].nb_ch;
         for (c = 0; c < 64; c++)
             for (i = 0; i < s->nb_inputs; i++)
-                if ((inlayout[i] >> c) & 1)
+                if (av_channel_layout_index_from_channel(inlayout[i], c) >= 0)
                     *(route[i]++) = out_ch_number++;
     }
     if ((ret = ff_set_common_formats_from_list(ctx, packed_sample_fmts)) < 0)
@@ -136,7 +139,7 @@ static int query_formats(AVFilterContext *ctx)
             return ret;
     }
     layouts = NULL;
-    if ((ret = ff_add_channel_layout(&layouts, outlayout)) < 0)
+    if ((ret = ff_add_channel_layout(&layouts, &outlayout)) < 0)
         return ret;
     if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
         return ret;
@@ -149,6 +152,7 @@ static int config_output(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AMergeContext *s = ctx->priv;
     AVBPrint bp;
+    char buf[128];
     int i;
 
     s->bps = av_get_bytes_per_sample(ctx->outputs[0]->format);
@@ -157,10 +161,12 @@ static int config_output(AVFilterLink *outlink)
     av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
     for (i = 0; i < s->nb_inputs; i++) {
         av_bprintf(&bp, "%sin%d:", i ? " + " : "", i);
-        av_bprint_channel_layout(&bp, -1, ctx->inputs[i]->channel_layout);
+        av_channel_layout_describe(&ctx->inputs[i]->ch_layout, buf, sizeof(buf));
+        av_bprintf(&bp, "%s", buf);
     }
     av_bprintf(&bp, " -> out:");
-    av_bprint_channel_layout(&bp, -1, ctx->outputs[0]->channel_layout);
+    av_channel_layout_describe(&ctx->outputs[0]->ch_layout, buf, sizeof(buf));
+    av_bprintf(&bp, "%s", buf);
     av_log(ctx, AV_LOG_VERBOSE, "%s\n", bp.str);
 
     return 0;
@@ -237,8 +243,14 @@ static int try_push_frame(AVFilterContext *ctx, int nb_samples)
     outbuf->pts = inbuf[0]->pts;
 
     outbuf->nb_samples     = nb_samples;
+    if ((ret = av_channel_layout_copy(&outbuf->ch_layout, &outlink->ch_layout)) < 0)
+        return ret;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     outbuf->channel_layout = outlink->channel_layout;
     outbuf->channels       = outlink->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     while (nb_samples) {
         /* Unroll the most common sample formats: speed +~350% for the loop,
diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index 3f51d43acd..097f637aac 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -282,7 +282,7 @@ static int config_output(AVFilterLink *outlink)
         s->scale_norm[i] = s->weight_sum / FFABS(s->weights[i]);
     calculate_scales(s, 0);
 
-    av_get_channel_layout_string(buf, sizeof(buf), -1, outlink->channel_layout);
+    av_channel_layout_describe(&outlink->ch_layout, buf, sizeof(buf));
 
     av_log(ctx, AV_LOG_VERBOSE,
            "inputs:%d fmt:%s srate:%d cl:%s\n", s->nb_inputs,
diff --git a/libavfilter/af_apulsator.c b/libavfilter/af_apulsator.c
index c2a8de0e0b..c3ca752035 100644
--- a/libavfilter/af_apulsator.c
+++ b/libavfilter/af_apulsator.c
@@ -192,7 +192,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
index 6e1be5b7eb..422c34d0e3 100644
--- a/libavfilter/af_aresample.c
+++ b/libavfilter/af_aresample.c
@@ -65,7 +65,8 @@ static int query_formats(AVFilterContext *ctx)
 {
     AResampleContext *aresample = ctx->priv;
     enum AVSampleFormat out_format;
-    int64_t out_rate, out_layout;
+    AVChannelLayout out_layout = { 0 };
+    int64_t out_rate;
 
     AVFilterLink *inlink  = ctx->inputs[0];
     AVFilterLink *outlink = ctx->outputs[0];
@@ -79,7 +80,7 @@ static int query_formats(AVFilterContext *ctx)
         av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0);
     av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
     av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
-    av_opt_get_int(aresample->swr, "ocl", 0, &out_layout);
+    av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout);
 
     in_formats      = ff_all_formats(AVMEDIA_TYPE_AUDIO);
     if ((ret = ff_formats_ref(in_formats, &inlink->outcfg.formats)) < 0)
@@ -111,8 +112,8 @@ static int query_formats(AVFilterContext *ctx)
     if ((ret = ff_formats_ref(out_formats, &outlink->incfg.formats)) < 0)
         return ret;
 
-    if(out_layout) {
-        int64_t layout_list[] = { out_layout, -1 };
+    if(av_channel_layout_check(&out_layout) && out_layout.order == AV_CHANNEL_ORDER_NATIVE) {
+        const AVChannelLayout layout_list[] = { out_layout, { 0 } };
         out_layouts = ff_make_format64_list(layout_list);
     } else
         out_layouts = ff_all_channel_counts();
@@ -127,38 +128,35 @@ static int config_output(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = ctx->inputs[0];
     AResampleContext *aresample = ctx->priv;
-    int64_t out_rate, out_layout;
+    AVChannelLayout out_layout = { 0 };
+    int64_t out_rate;
     enum AVSampleFormat out_format;
     char inchl_buf[128], outchl_buf[128];
 
-    aresample->swr = swr_alloc_set_opts(aresample->swr,
-                                        outlink->channel_layout, outlink->format, outlink->sample_rate,
-                                        inlink->channel_layout, inlink->format, inlink->sample_rate,
-                                        0, ctx);
-    if (!aresample->swr)
-        return AVERROR(ENOMEM);
-    if (!inlink->channel_layout)
-        av_opt_set_int(aresample->swr, "ich", inlink->channels, 0);
-    if (!outlink->channel_layout)
-        av_opt_set_int(aresample->swr, "och", outlink->channels, 0);
+    ret = swr_alloc_set_opts2(&aresample->swr,
+                              &outlink->ch_layout, outlink->format, outlink->sample_rate,
+                              &inlink->ch_layout, inlink->format, inlink->sample_rate,
+                                         0, ctx);
+    if (ret < 0)
+        return ret;
 
     ret = swr_init(aresample->swr);
     if (ret < 0)
         return ret;
 
     av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
-    av_opt_get_int(aresample->swr, "ocl", 0, &out_layout);
+    av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout);
     av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
     outlink->time_base = (AVRational) {1, out_rate};
 
     av_assert0(outlink->sample_rate == out_rate);
-    av_assert0(outlink->channel_layout == out_layout || !outlink->channel_layout);
+    av_assert0(!av_channel_layout_compare(&outlink->ch_layout, &out_layout));
     av_assert0(outlink->format == out_format);
 
     aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate;
 
-    av_get_channel_layout_string(inchl_buf,  sizeof(inchl_buf),  inlink ->channels, inlink ->channel_layout);
-    av_get_channel_layout_string(outchl_buf, sizeof(outchl_buf), outlink->channels, outlink->channel_layout);
+    av_channel_layout_describe(&inlink ->ch_layout, inchl_buf,  sizeof(inchl_buf));
+    av_channel_layout_describe(&outlink->ch_layout, outchl_buf, sizeof(outchl_buf));
 
     av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s fmt:%s r:%dHz\n",
            inlink ->channels, inchl_buf,  av_get_sample_fmt_name(inlink->format),  inlink->sample_rate,
@@ -189,8 +187,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
 
     av_frame_copy_props(outsamplesref, insamplesref);
     outsamplesref->format                = outlink->format;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     outsamplesref->channels              = outlink->channels;
     outsamplesref->channel_layout        = outlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    outsamplesref->ch_layout             = outlink->ch_layout;
     outsamplesref->sample_rate           = outlink->sample_rate;
 
     if(insamplesref->pts != AV_NOPTS_VALUE) {
diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c
index c76756db63..949f0e52a4 100644
--- a/libavfilter/af_ashowinfo.c
+++ b/libavfilter/af_ashowinfo.c
@@ -178,6 +178,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 {
     AVFilterContext *ctx = inlink->dst;
     AShowInfoContext *s  = ctx->priv;
+#if FF_API_OLD_CHANNEL_LAYOUT
+    AVChannelLayout layout = { 0 };
+#endif
     char chlayout_str[128];
     uint32_t checksum = 0;
     int channels    = inlink->channels;
@@ -200,8 +203,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
                        s->plane_checksums[0];
     }
 
-    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), buf->channels,
-                                 buf->channel_layout);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (av_channel_layout_from_mask(&layout, buf->channel_layout)) {
+        av_channel_layout_describe(&layout, chlayout_str, sizeof(chlayout_str));
+FF_ENABLE_DEPRECATION_WARNINGS
+    } else if (buf->ch_layout.nb_channels)
+#endif
+    av_channel_layout_describe(&buf->ch_layout, chlayout_str, sizeof(chlayout_str));
 
     av_log(ctx, AV_LOG_INFO,
            "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
diff --git a/libavfilter/af_asr.c b/libavfilter/af_asr.c
index 42250e79e2..b402f5ff26 100644
--- a/libavfilter/af_asr.c
+++ b/libavfilter/af_asr.c
@@ -131,7 +131,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_S16                 )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats                           )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_MONO                 )) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO )) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout                            )) < 0 ||
         (ret = ff_set_common_samplerates_from_list(ctx, sample_rates     )) < 0)
         return ret;
diff --git a/libavfilter/af_biquads.c b/libavfilter/af_biquads.c
index ee42b2a034..a655d21226 100644
--- a/libavfilter/af_biquads.c
+++ b/libavfilter/af_biquads.c
@@ -125,7 +125,7 @@ typedef struct BiquadsContext {
     double frequency;
     double width;
     double mix;
-    uint64_t channels;
+    AVChannelLayout ch_layout;
     int normalize;
     int order;
 
@@ -843,7 +843,9 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job
     int ch;
 
     for (ch = start; ch < end; ch++) {
-        if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
+        if (!(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 &&
+              av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0)) {
+
             if (buf != out_buf)
                 memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
                        buf->nb_samples * s->block_align);
@@ -982,8 +984,8 @@ static const AVOption equalizer_options[] = {
     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1024,8 +1026,8 @@ static const AVOption bass_lowshelf_options[] = {
     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1073,8 +1075,8 @@ static const AVOption treble_highshelf_options[] = {
     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1121,8 +1123,8 @@ static const AVOption bandpass_options[] = {
     {"csg",   "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1159,8 +1161,8 @@ static const AVOption bandreject_options[] = {
     {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1199,8 +1201,8 @@ static const AVOption lowpass_options[] = {
     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1239,8 +1241,8 @@ static const AVOption highpass_options[] = {
     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1277,8 +1279,8 @@ static const AVOption allpass_options[] = {
     {"w",     "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
@@ -1312,8 +1314,8 @@ static const AVOption biquad_options[] = {
     {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
diff --git a/libavfilter/af_bs2b.c b/libavfilter/af_bs2b.c
index 90ae846d95..20e6d8141a 100644
--- a/libavfilter/af_bs2b.c
+++ b/libavfilter/af_bs2b.c
@@ -104,7 +104,7 @@ static int query_formats(AVFilterContext *ctx)
     };
     int ret;
 
-    if (ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO) != 0)
+    if (ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) != 0)
         return AVERROR(ENOMEM);
     ret = ff_set_common_channel_layouts(ctx, layouts);
     if (ret < 0)
diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c
index d3ab77920f..c8d259a9ff 100644
--- a/libavfilter/af_channelmap.c
+++ b/libavfilter/af_channelmap.c
@@ -38,8 +38,8 @@
 #include "internal.h"
 
 struct ChannelMap {
-    uint64_t in_channel;
-    uint64_t out_channel;
+    int in_channel;
+    int out_channel;
     int in_channel_idx;
     int out_channel_idx;
 };
@@ -59,7 +59,7 @@ typedef struct ChannelMapContext {
     const AVClass *class;
     char *mapping_str;
     char *channel_layout_str;
-    uint64_t output_layout;
+    AVChannelLayout output_layout;
     struct ChannelMap map[MAX_CH];
     int nch;
     enum MappingMode mode;
@@ -105,13 +105,13 @@ static int get_channel_idx(char **map, int *ch, char delim, int max_ch)
     return 0;
 }
 
-static int get_channel(char **map, uint64_t *ch, char delim)
+static int get_channel(char **map, int *ch, char delim)
 {
     char *next = split(*map, delim);
     if (!next && delim == '-')
         return AVERROR(EINVAL);
-    *ch = av_get_channel_layout(*map);
-    if (av_get_channel_layout_nb_channels(*ch) != 1)
+    *ch = av_channel_from_string(*map);
+    if (*ch < 0)
         return AVERROR(EINVAL);
     *map = next;
     return 0;
@@ -167,7 +167,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
 
     for (i = 0; i < map_entries; i++) {
         int in_ch_idx = -1, out_ch_idx = -1;
-        uint64_t in_ch = 0, out_ch = 0;
+        int in_ch = 0, out_ch = 0;
         static const char err[] = "Failed to parse channel map\n";
         switch (mode) {
         case MAP_ONE_INT:
@@ -198,13 +198,13 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
         case MAP_PAIR_INT_STR:
             if (get_channel_idx(&mapping, &in_ch_idx, '-', MAX_CH) < 0 ||
                 get_channel(&mapping, &out_ch, separator) < 0 ||
-                out_ch & out_ch_mask) {
+                (1ULL << out_ch) & out_ch_mask) {
                 av_log(ctx, AV_LOG_ERROR, err);
                 return AVERROR(EINVAL);
             }
             s->map[i].in_channel_idx  = in_ch_idx;
             s->map[i].out_channel     = out_ch;
-            out_ch_mask |= out_ch;
+            out_ch_mask |= 1ULL << out_ch;
             break;
         case MAP_PAIR_STR_INT:
             if (get_channel(&mapping, &in_ch, '-') < 0 ||
@@ -218,42 +218,57 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
         case MAP_PAIR_STR_STR:
             if (get_channel(&mapping, &in_ch, '-') < 0 ||
                 get_channel(&mapping, &out_ch, separator) < 0 ||
-                out_ch & out_ch_mask) {
+                (1ULL << out_ch) & out_ch_mask) {
                 av_log(ctx, AV_LOG_ERROR, err);
                 return AVERROR(EINVAL);
             }
             s->map[i].in_channel = in_ch;
             s->map[i].out_channel = out_ch;
-            out_ch_mask |= out_ch;
+            out_ch_mask |= 1ULL << out_ch;
             break;
         }
     }
     s->mode          = mode;
     s->nch           = map_entries;
-    s->output_layout = out_ch_mask ? out_ch_mask :
-                       av_get_default_channel_layout(map_entries);
+    if (out_ch_mask)
+        av_channel_layout_from_mask(&s->output_layout, out_ch_mask);
+    else
+        av_channel_layout_default(&s->output_layout, map_entries);
 
     if (s->channel_layout_str) {
-        uint64_t fmt;
-        if ((fmt = av_get_channel_layout(s->channel_layout_str)) == 0) {
-            av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n",
+        AVChannelLayout fmt = { 0 };
+        int ret;
+        if ((ret = av_channel_layout_from_string(&fmt, s->channel_layout_str)) < 0) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+            uint64_t mask;
+FF_DISABLE_DEPRECATION_WARNINGS
+            if ((mask = av_get_channel_layout(s->channel_layout_str)) == 0) {
+#endif
+                av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n",
+                       s->channel_layout_str);
+                return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+            }
+FF_ENABLE_DEPRECATION_WARNINGS
+            av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
                    s->channel_layout_str);
-            return AVERROR(EINVAL);
+            av_channel_layout_from_mask(&fmt, mask);
+#endif
         }
         if (mode == MAP_NONE) {
             int i;
-            s->nch = av_get_channel_layout_nb_channels(fmt);
+            s->nch = fmt.nb_channels;
             for (i = 0; i < s->nch; i++) {
                 s->map[i].in_channel_idx  = i;
                 s->map[i].out_channel_idx = i;
             }
-        } else if (out_ch_mask && out_ch_mask != fmt) {
-            av_get_channel_layout_string(buf, sizeof(buf), 0, out_ch_mask);
+        } else if (out_ch_mask && av_channel_layout_compare(&s->output_layout, &fmt)) {
+            av_channel_layout_describe(&s->output_layout, buf, sizeof(buf));
             av_log(ctx, AV_LOG_ERROR,
                    "Output channel layout '%s' does not match the list of channel mapped: '%s'.\n",
                    s->channel_layout_str, buf);
             return AVERROR(EINVAL);
-        } else if (s->nch != av_get_channel_layout_nb_channels(fmt)) {
+        } else if (s->nch != fmt.nb_channels) {
             av_log(ctx, AV_LOG_ERROR,
                    "Output channel layout %s does not match the number of channels mapped %d.\n",
                    s->channel_layout_str, s->nch);
@@ -261,7 +276,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
         }
         s->output_layout = fmt;
     }
-    if (!s->output_layout) {
+    if (!s->output_layout.nb_channels) {
         av_log(ctx, AV_LOG_ERROR, "Output channel layout is not set and "
                "cannot be guessed from the maps.\n");
         return AVERROR(EINVAL);
@@ -269,8 +284,8 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
 
     if (mode == MAP_PAIR_INT_STR || mode == MAP_PAIR_STR_STR) {
         for (i = 0; i < s->nch; i++) {
-            s->map[i].out_channel_idx = av_get_channel_layout_channel_index(
-                s->output_layout, s->map[i].out_channel);
+            s->map[i].out_channel_idx = av_channel_layout_index_from_channel(
+                &s->output_layout, s->map[i].out_channel);
         }
     }
 
@@ -285,7 +300,7 @@ static int channelmap_query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_set_common_formats    (ctx,  ff_planar_sample_fmts()))  < 0 ||
         (ret = ff_set_common_all_samplerates(ctx                              )) < 0 ||
-        (ret = ff_add_channel_layout(&channel_layouts, s->output_layout)) < 0 ||
+        (ret = ff_add_channel_layout(&channel_layouts, &s->output_layout)) < 0 ||
         (ret = ff_channel_layouts_ref(channel_layouts,
                                       &ctx->outputs[0]->incfg.channel_layouts)) < 0)
         return ret;
@@ -301,7 +316,7 @@ static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf)
     const ChannelMapContext *s = ctx->priv;
     const int nch_in = inlink->channels;
     const int nch_out = s->nch;
-    int ch;
+    int ch, ret;
     uint8_t *source_planes[MAX_CH];
 
     memcpy(source_planes, buf->extended_data,
@@ -336,7 +351,13 @@ static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf)
         memcpy(buf->data, buf->extended_data,
            FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     buf->channel_layout = outlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&buf->ch_layout, &outlink->ch_layout)) < 0)
+        return ret;
     buf->channels       = outlink->channels;
 
     return ff_filter_frame(outlink, buf);
@@ -346,24 +367,23 @@ static int channelmap_config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     ChannelMapContext *s = ctx->priv;
-    int nb_channels = inlink->channels;
+    int nb_channels = inlink->ch_layout.nb_channels;
     int i, err = 0;
-    const char *channel_name;
+    char channel_name[64];
     char layout_name[256];
 
     for (i = 0; i < s->nch; i++) {
         struct ChannelMap *m = &s->map[i];
 
         if (s->mode == MAP_PAIR_STR_INT || s->mode == MAP_PAIR_STR_STR) {
-            m->in_channel_idx = av_get_channel_layout_channel_index(
-                inlink->channel_layout, m->in_channel);
+            m->in_channel_idx = av_channel_layout_index_from_channel(
+                &inlink->ch_layout, m->in_channel);
         }
 
         if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) {
-            av_get_channel_layout_string(layout_name, sizeof(layout_name),
-                                         nb_channels, inlink->channel_layout);
+            av_channel_layout_describe(&inlink->ch_layout, layout_name, sizeof(layout_name));
             if (m->in_channel) {
-                channel_name = av_get_channel_name(m->in_channel);
+                av_channel_name(channel_name, sizeof(channel_name), m->in_channel);
                 av_log(ctx, AV_LOG_ERROR,
                        "input channel '%s' not available from input layout '%s'\n",
                        channel_name, layout_name);
diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c
index 1a2519dd32..099ba097e2 100644
--- a/libavfilter/af_channelsplit.c
+++ b/libavfilter/af_channelsplit.c
@@ -36,7 +36,7 @@
 typedef struct ChannelSplitContext {
     const AVClass *class;
 
-    uint64_t channel_layout;
+    AVChannelLayout channel_layout;
     char    *channel_layout_str;
     char    *channels_str;
 
@@ -57,11 +57,11 @@ AVFILTER_DEFINE_CLASS(channelsplit);
 static av_cold int init(AVFilterContext *ctx)
 {
     ChannelSplitContext *s = ctx->priv;
-    uint64_t channel_layout;
+    AVChannelLayout channel_layout = { 0 };
     int nb_channels;
     int all = 0, ret = 0, i;
 
-    if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) {
+    if ((ret = av_channel_layout_from_string(&s->channel_layout, s->channel_layout_str)) < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
                s->channel_layout_str);
         ret = AVERROR(EINVAL);
@@ -70,27 +70,32 @@ static av_cold int init(AVFilterContext *ctx)
 
 
     if (!strcmp(s->channels_str, "all")) {
-        nb_channels = av_get_channel_layout_nb_channels(s->channel_layout);
+        nb_channels = s->channel_layout.nb_channels;
         channel_layout = s->channel_layout;
         all = 1;
     } else {
-        if ((ret = av_get_extended_channel_layout(s->channels_str, &channel_layout, &nb_channels)) < 0)
+        if ((ret = av_channel_layout_from_string(&channel_layout, s->channels_str)) < 0)
             return ret;
     }
 
     for (i = 0; i < nb_channels; i++) {
-        uint64_t channel = av_channel_layout_extract_channel(channel_layout, i);
-        AVFilterPad pad  = { 0 };
+        int channel = av_channel_layout_channel_from_index(&channel_layout, i);
+        char buf[64];
+        AVFilterPad pad = { .flags = AVFILTERPAD_FLAG_FREE_NAME };
 
+        av_channel_name(buf, sizeof(buf), channel);
         pad.type = AVMEDIA_TYPE_AUDIO;
-        pad.name = av_get_channel_name(channel);
+        pad.name = av_strdup(buf);
+        if (!pad.name)
+            return AVERROR(ENOMEM);
 
         if (all) {
             s->map[i] = i;
         } else {
-            if ((ret = av_get_channel_layout_channel_index(s->channel_layout, channel)) < 0) {
+            if ((ret = av_channel_layout_index_from_channel(&s->channel_layout, channel)) < 0) {
                 av_log(ctx, AV_LOG_ERROR, "Channel name '%s' not present in channel layout '%s'.\n",
-                       av_get_channel_name(channel), s->channel_layout_str);
+                       pad.name, s->channel_layout_str);
+                av_freep(&pad.name);
                 return ret;
             }
 
@@ -115,15 +120,18 @@ static int query_formats(AVFilterContext *ctx)
         (ret = ff_set_common_all_samplerates(ctx)) < 0)
         return ret;
 
-    if ((ret = ff_add_channel_layout(&in_layouts, s->channel_layout)) < 0 ||
+    if ((ret = ff_add_channel_layout(&in_layouts, &s->channel_layout)) < 0 ||
         (ret = ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->outcfg.channel_layouts)) < 0)
         return ret;
 
     for (i = 0; i < ctx->nb_outputs; i++) {
+        AVChannelLayout channel_layout = { 0 };
         AVFilterChannelLayouts *out_layouts = NULL;
-        uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, s->map[i]);
+        int channel = av_channel_layout_channel_from_index(&s->channel_layout, s->map[i]);
 
-        if ((ret = ff_add_channel_layout(&out_layouts, channel)) < 0 ||
+        if ((channel < 0) ||
+            (ret = av_channel_layout_from_mask(&channel_layout, 1ULL << channel)) < 0 ||
+            (ret = ff_add_channel_layout(&out_layouts, &channel_layout)) < 0 ||
             (ret = ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->incfg.channel_layouts)) < 0)
             return ret;
     }
@@ -139,6 +147,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 
     for (i = 0; i < ctx->nb_outputs; i++) {
         AVFrame *buf_out = av_frame_clone(buf);
+        int channel = av_channel_layout_channel_from_index(&buf->ch_layout, s->map[i]);
 
         if (!buf_out) {
             ret = AVERROR(ENOMEM);
@@ -146,8 +155,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
         }
 
         buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[s->map[i]];
+        ret = av_channel_layout_from_mask(&buf_out->ch_layout, 1ULL << channel);
+        if (ret < 0)
+            break;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
         buf_out->channel_layout =
             av_channel_layout_extract_channel(buf->channel_layout, s->map[i]);
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         buf_out->channels = 1;
 
         ret = ff_filter_frame(ctx->outputs[i], buf_out);
diff --git a/libavfilter/af_compand.c b/libavfilter/af_compand.c
index 2f8a580279..31e1a0b548 100644
--- a/libavfilter/af_compand.c
+++ b/libavfilter/af_compand.c
@@ -503,7 +503,13 @@ static int config_output(AVFilterLink *outlink)
 
     s->delay_frame->format         = outlink->format;
     s->delay_frame->nb_samples     = s->delay_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     s->delay_frame->channel_layout = outlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((err = av_channel_layout_copy(&s->delay_frame->ch_layout, &outlink->ch_layout)) < 0)
+        return err;
 
     err = av_frame_get_buffer(s->delay_frame, 0);
     if (err)
diff --git a/libavfilter/af_compensationdelay.c b/libavfilter/af_compensationdelay.c
index 6a58fd21bd..94b9447df2 100644
--- a/libavfilter/af_compensationdelay.c
+++ b/libavfilter/af_compensationdelay.c
@@ -68,6 +68,7 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     CompensationDelayContext *s = ctx->priv;
     unsigned min_size, new_size = 1;
+    int ret;
 
     s->delay = (s->distance_m * 100. + s->distance_cm * 1. + s->distance_mm * .1) *
                COMP_DELAY_SOUND_FRONT_DELAY(s->temp) * inlink->sample_rate;
@@ -83,7 +84,13 @@ static int config_input(AVFilterLink *inlink)
     s->buf_size                    = new_size;
     s->delay_frame->format         = inlink->format;
     s->delay_frame->nb_samples     = new_size;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     s->delay_frame->channel_layout = inlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&s->delay_frame->ch_layout, &inlink->ch_layout)) < 0)
+        return ret;
 
     return av_frame_get_buffer(s->delay_frame, 0);
 }
diff --git a/libavfilter/af_crossfeed.c b/libavfilter/af_crossfeed.c
index ecfbb978d4..15990703e1 100644
--- a/libavfilter/af_crossfeed.c
+++ b/libavfilter/af_crossfeed.c
@@ -46,7 +46,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0 ||
         (ret = ff_set_common_all_samplerates (ctx                          )) < 0)
         return ret;
diff --git a/libavfilter/af_earwax.c b/libavfilter/af_earwax.c
index fa0162abb2..f420a5ac55 100644
--- a/libavfilter/af_earwax.c
+++ b/libavfilter/af_earwax.c
@@ -88,7 +88,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_S16P                )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats                           )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO               )) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout                            )) < 0 ||
         (ret = ff_set_common_samplerates_from_list(ctx, sample_rates)) < 0)
         return ret;
diff --git a/libavfilter/af_extrastereo.c b/libavfilter/af_extrastereo.c
index 1645ccb944..6f1d691d8e 100644
--- a/libavfilter/af_extrastereo.c
+++ b/libavfilter/af_extrastereo.c
@@ -49,7 +49,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_firequalizer.c b/libavfilter/af_firequalizer.c
index 568b78117a..cf63d0f21c 100644
--- a/libavfilter/af_firequalizer.c
+++ b/libavfilter/af_firequalizer.c
@@ -608,13 +608,14 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g
         av_log(ctx, AV_LOG_WARNING, "dumping failed.\n");
 
     vars[VAR_CHS] = inlink->channels;
-    vars[VAR_CHLAYOUT] = inlink->channel_layout;
+    vars[VAR_CHLAYOUT] = inlink->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                         inlink->ch_layout.u.mask : 0;
     vars[VAR_SR] = inlink->sample_rate;
     for (ch = 0; ch < inlink->channels; ch++) {
         float *rdft_buf = s->kernel_tmp_buf + ch * s->rdft_len;
         double result;
         vars[VAR_CH] = ch;
-        vars[VAR_CHID] = av_channel_layout_extract_channel(inlink->channel_layout, ch);
+        vars[VAR_CHID] = av_channel_layout_channel_from_index(&inlink->ch_layout, ch);
         vars[VAR_F] = 0.0;
         if (xlog)
             vars[VAR_F] = log2(0.05 * vars[VAR_F]);
diff --git a/libavfilter/af_haas.c b/libavfilter/af_haas.c
index 281ec276f9..d283da7261 100644
--- a/libavfilter/af_haas.c
+++ b/libavfilter/af_haas.c
@@ -87,7 +87,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c
index 494642106d..08907e718e 100644
--- a/libavfilter/af_hdcd.c
+++ b/libavfilter/af_hdcd.c
@@ -1627,10 +1627,10 @@ static int query_formats(AVFilterContext *ctx)
     };
     int ret;
 
-    ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_MONO);
+    ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO);
     if (ret < 0)
         return ret;
-    ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO);
+    ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
     if (ret < 0)
         return ret;
 
diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index b2030dbbbb..15bada4315 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -85,13 +85,13 @@ typedef struct HeadphoneContext {
     uint64_t mapping[64];
 } HeadphoneContext;
 
-static int parse_channel_name(const char *arg, uint64_t *rchannel)
+static int parse_channel_name(const char *arg, int *rchannel)
 {
-    uint64_t layout = av_get_channel_layout(arg);
+    int channel = av_channel_from_string(arg);
 
-    if (av_get_channel_layout_nb_channels(layout) != 1)
+    if (channel < 0)
         return AVERROR(EINVAL);
-    *rchannel = layout;
+    *rchannel = channel;
     return 0;
 }
 
@@ -103,14 +103,14 @@ static void parse_map(AVFilterContext *ctx)
 
     p = s->map;
     while ((arg = av_strtok(p, "|", &tokenizer))) {
-        uint64_t out_channel;
+        int out_channel;
 
         p = NULL;
         if (parse_channel_name(arg, &out_channel)) {
             av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg);
             continue;
         }
-        if (used_channels & out_channel) {
+        if (used_channels & (1ULL << out_channel)) {
             av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", arg);
             continue;
         }
@@ -451,7 +451,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
         ptr = (float *)frame->extended_data[0];
 
         if (s->hrir_fmt == HRIR_STEREO) {
-            int idx = av_get_channel_layout_channel_index(inlink->channel_layout,
+            int idx = av_channel_layout_index_from_channel(&inlink->ch_layout,
                                                           s->mapping[i]);
             if (idx < 0)
                 continue;
@@ -481,7 +481,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
             int I, N = ctx->inputs[1]->channels;
 
             for (k = 0; k < N / 2; k++) {
-                int idx = av_get_channel_layout_channel_index(inlink->channel_layout,
+                int idx = av_channel_layout_index_from_channel(&inlink->ch_layout,
                                                               s->mapping[k]);
                 if (idx < 0)
                     continue;
@@ -602,7 +602,7 @@ static int query_formats(AVFilterContext *ctx)
     if (ret)
         return ret;
 
-    ret = ff_add_channel_layout(&stereo_layout, AV_CH_LAYOUT_STEREO);
+    ret = ff_add_channel_layout(&stereo_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
     if (ret)
         return ret;
     ret = ff_channel_layouts_ref(stereo_layout, &ctx->outputs[0]->incfg.channel_layouts);
@@ -637,8 +637,8 @@ static int config_input(AVFilterLink *inlink)
         return AVERROR(EINVAL);
     }
 
-    s->lfe_channel = av_get_channel_layout_channel_index(inlink->channel_layout,
-                                                         AV_CH_LOW_FREQUENCY);
+    s->lfe_channel = av_channel_layout_index_from_channel(&inlink->ch_layout,
+                                                          AV_CHAN_LOW_FREQUENCY);
     return 0;
 }
 
diff --git a/libavfilter/af_join.c b/libavfilter/af_join.c
index 6cc21f465c..05fc69e67e 100644
--- a/libavfilter/af_join.c
+++ b/libavfilter/af_join.c
@@ -24,6 +24,7 @@
  * a single output
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
@@ -36,10 +37,10 @@
 #include "internal.h"
 
 typedef struct ChannelMap {
-    int input;                ///< input stream index
-    int       in_channel_idx; ///< index of in_channel in the input stream data
-    uint64_t  in_channel;     ///< layout describing the input channel
-    uint64_t out_channel;     ///< layout describing the output channel
+    int input;                     ///< input stream index
+    int            in_channel_idx; ///< index of in_channel in the input stream data
+    enum AVChannel in_channel;
+    enum AVChannel out_channel;
 } ChannelMap;
 
 typedef struct JoinContext {
@@ -48,11 +49,10 @@ typedef struct JoinContext {
     int inputs;
     char *map;
     char    *channel_layout_str;
-    uint64_t channel_layout;
+    AVChannelLayout ch_layout;
 
     int64_t  eof_pts;
 
-    int      nb_channels;
     ChannelMap *channels;
 
     /**
@@ -79,20 +79,21 @@ static const AVOption join_options[] = {
     { NULL }
 };
 
+#define MAP_SEPARATOR '|'
+
 AVFILTER_DEFINE_CLASS(join);
 
 static int parse_maps(AVFilterContext *ctx)
 {
     JoinContext *s = ctx->priv;
-    char separator = '|';
     char *cur      = s->map;
 
     while (cur && *cur) {
+        ChannelMap *map;
         char *sep, *next, *p;
-        uint64_t in_channel = 0, out_channel = 0;
-        int input_idx, out_ch_idx, in_ch_idx;
+        int input_idx, out_ch_idx;
 
-        next = strchr(cur, separator);
+        next = strchr(cur, MAP_SEPARATOR);
         if (next)
             *next++ = 0;
 
@@ -104,28 +105,16 @@ static int parse_maps(AVFilterContext *ctx)
         }
         *sep++ = 0;
 
-#define PARSE_CHANNEL(str, var, inout)                                         \
-        if (!(var = av_get_channel_layout(str))) {                             \
-            av_log(ctx, AV_LOG_ERROR, "Invalid " inout " channel: %s.\n", str);\
-            return AVERROR(EINVAL);                                            \
-        }                                                                      \
-        if (av_get_channel_layout_nb_channels(var) != 1) {                     \
-            av_log(ctx, AV_LOG_ERROR, "Channel map describes more than one "   \
-                   inout " channel.\n");                                       \
-            return AVERROR(EINVAL);                                            \
-        }
-
         /* parse output channel */
-        PARSE_CHANNEL(sep, out_channel, "output");
-        if (!(out_channel & s->channel_layout)) {
-            av_log(ctx, AV_LOG_ERROR, "Output channel '%s' is not present in "
-                   "requested channel layout.\n", sep);
+        out_ch_idx = av_channel_layout_index_from_string(&s->ch_layout, sep);
+        if (out_ch_idx < 0) {
+            av_log(ctx, AV_LOG_ERROR, "Invalid output channel: %s.\n", sep);
             return AVERROR(EINVAL);
         }
 
-        out_ch_idx = av_get_channel_layout_channel_index(s->channel_layout,
-                                                         out_channel);
-        if (s->channels[out_ch_idx].input >= 0) {
+        map = &s->channels[out_ch_idx];
+
+        if (map->input >= 0) {
             av_log(ctx, AV_LOG_ERROR, "Multiple maps for output channel "
                    "'%s'.\n", sep);
             return AVERROR(EINVAL);
@@ -142,19 +131,21 @@ static int parse_maps(AVFilterContext *ctx)
         if (*cur)
             cur++;
 
-        in_ch_idx = strtol(cur, &p, 0);
+        map->input          = input_idx;
+        map->in_channel     = AV_CHAN_NONE;
+        map->in_channel_idx = strtol(cur, &p, 0);
         if (p == cur) {
-            /* channel specifier is not a number,
-             * try to parse as channel name */
-            PARSE_CHANNEL(cur, in_channel, "input");
+            /* channel specifier is not a number, handle as channel name */
+            map->in_channel = av_channel_from_string(cur);
+            if (map->in_channel < 0) {
+                av_log(ctx, AV_LOG_ERROR, "Invalid input channel: %s.\n", cur);
+                return AVERROR(EINVAL);
+            }
+        } else if (map->in_channel_idx < 0) {
+            av_log(ctx, AV_LOG_ERROR, "Invalid input channel index: %d\n", map->in_channel_idx);
+            return AVERROR(EINVAL);
         }
 
-        s->channels[out_ch_idx].input      = input_idx;
-        if (in_channel)
-            s->channels[out_ch_idx].in_channel = in_channel;
-        else
-            s->channels[out_ch_idx].in_channel_idx = in_ch_idx;
-
         cur = next;
     }
     return 0;
@@ -165,22 +156,37 @@ static av_cold int join_init(AVFilterContext *ctx)
     JoinContext *s = ctx->priv;
     int ret, i;
 
-    if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) {
-        av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
+    ret = av_channel_layout_from_string(&s->ch_layout, s->channel_layout_str);
+    if (ret < 0) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+        uint64_t mask;
+FF_DISABLE_DEPRECATION_WARNINGS
+        mask = av_get_channel_layout(s->channel_layout_str);
+        if (!mask) {
+#endif
+            av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
+                   s->channel_layout_str);
+            return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+        av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
                s->channel_layout_str);
-        return AVERROR(EINVAL);
+        av_channel_layout_from_mask(&s->ch_layout, mask);
+#endif
     }
 
-    s->nb_channels  = av_get_channel_layout_nb_channels(s->channel_layout);
-    s->channels     = av_calloc(s->nb_channels, sizeof(*s->channels));
-    s->buffers      = av_calloc(s->nb_channels, sizeof(*s->buffers));
+    s->channels     = av_calloc(s->ch_layout.nb_channels, sizeof(*s->channels));
+    s->buffers      = av_calloc(s->ch_layout.nb_channels, sizeof(*s->buffers));
     s->input_frames = av_calloc(s->inputs, sizeof(*s->input_frames));
     if (!s->channels || !s->buffers|| !s->input_frames)
         return AVERROR(ENOMEM);
 
-    for (i = 0; i < s->nb_channels; i++) {
-        s->channels[i].out_channel = av_channel_layout_extract_channel(s->channel_layout, i);
-        s->channels[i].input       = -1;
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
+        s->channels[i].out_channel    = av_channel_layout_channel_from_index(&s->ch_layout, i);
+        s->channels[i].input          = -1;
+        s->channels[i].in_channel_idx = -1;
+        s->channels[i].in_channel     = AV_CHAN_NONE;
     }
 
     if ((ret = parse_maps(ctx)) < 0)
@@ -221,7 +227,7 @@ static int join_query_formats(AVFilterContext *ctx)
     AVFilterChannelLayouts *layouts = NULL;
     int i, ret;
 
-    if ((ret = ff_add_channel_layout(&layouts, s->channel_layout)) < 0 ||
+    if ((ret = ff_add_channel_layout(&layouts, &s->ch_layout)) < 0 ||
         (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
         return ret;
 
@@ -238,38 +244,55 @@ static int join_query_formats(AVFilterContext *ctx)
     return 0;
 }
 
+typedef struct ChannelList {
+    enum AVChannel *ch;
+    int          nb_ch;
+} ChannelList;
+
+static enum AVChannel channel_list_pop(ChannelList *chl, int idx)
+{
+    enum AVChannel ret = chl->ch[idx];
+    memcpy(chl->ch + idx, chl->ch + idx + 1,
+           (chl->nb_ch - idx - 1) * sizeof(*chl->ch));
+    chl->nb_ch--;
+    return ret;
+}
+
+/*
+ * If ch is present in chl, remove it from the list and return it.
+ * Otherwise return AV_CHAN_NONE.
+ */
+static enum AVChannel channel_list_pop_ch(ChannelList *chl, enum AVChannel ch)
+{
+    for (int i = 0; i < chl->nb_ch; i++)
+        if (chl->ch[i] == ch)
+            return channel_list_pop(chl, i);
+    return AV_CHAN_NONE;
+}
+
 static void guess_map_matching(AVFilterContext *ctx, ChannelMap *ch,
-                               uint64_t *inputs)
+                               ChannelList *inputs)
 {
     int i;
 
     for (i = 0; i < ctx->nb_inputs; i++) {
-        AVFilterLink *link = ctx->inputs[i];
-
-        if (ch->out_channel & link->channel_layout &&
-            !(ch->out_channel & inputs[i])) {
+        if (channel_list_pop_ch(&inputs[i], ch->out_channel) != AV_CHAN_NONE) {
             ch->input      = i;
             ch->in_channel = ch->out_channel;
-            inputs[i]     |= ch->out_channel;
             return;
         }
     }
 }
 
 static void guess_map_any(AVFilterContext *ctx, ChannelMap *ch,
-                          uint64_t *inputs)
+                          ChannelList *inputs)
 {
     int i;
 
     for (i = 0; i < ctx->nb_inputs; i++) {
-        AVFilterLink *link = ctx->inputs[i];
-
-        if ((inputs[i] & link->channel_layout) != link->channel_layout) {
-            uint64_t unused = link->channel_layout & ~inputs[i];
-
+        if (inputs[i].nb_ch) {
             ch->input      = i;
-            ch->in_channel = av_channel_layout_extract_channel(unused, 0);
-            inputs[i]     |= ch->in_channel;
+            ch->in_channel = channel_list_pop(&inputs[i], 0);
             return;
         }
     }
@@ -279,81 +302,136 @@ static int join_config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     JoinContext       *s = ctx->priv;
-    uint64_t *inputs;   // nth element tracks which channels are used from nth input
+    // unused channels from each input
+    ChannelList *inputs_unused;
+    char inbuf[64], outbuf[64];
     int i, ret = 0;
 
-    /* initialize inputs to user-specified mappings */
-    if (!(inputs = av_calloc(ctx->nb_inputs, sizeof(*inputs))))
+    /* initialize unused channel list for each input */
+    inputs_unused = av_calloc(ctx->nb_inputs, sizeof(*inputs_unused));
+    if (!inputs_unused)
         return AVERROR(ENOMEM);
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < ctx->nb_inputs; i++) {
+        AVFilterLink *inlink = ctx->inputs[i];
+        AVChannelLayout *chl = &inlink->ch_layout;
+        ChannelList      *iu = &inputs_unused[i];
+
+        iu->nb_ch = chl->nb_channels;
+        iu->ch    = av_malloc_array(iu->nb_ch, sizeof(*iu->ch));
+        if (!iu->ch) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+
+        for (int ch_idx = 0; ch_idx < iu->nb_ch; ch_idx++) {
+            iu->ch[ch_idx] = av_channel_layout_channel_from_index(chl, ch_idx);
+            if (iu->ch[ch_idx] < 0) {
+                /* no channel ordering information in this input,
+                 * so don't auto-map from it */
+                iu->nb_ch = 0;
+                break;
+            }
+        }
+    }
+
+    /* process user-specified maps */
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
         AVFilterLink *inlink;
+        AVChannelLayout *ichl;
+        ChannelList     *iu;
 
         if (ch->input < 0)
             continue;
 
         inlink = ctx->inputs[ch->input];
+        ichl   = &inlink->ch_layout;
+        iu     = &inputs_unused[ch->input];
+
+        /* get the index for the channels defined by name */
+        if (ch->in_channel != AV_CHAN_NONE) {
+            ch->in_channel_idx = av_channel_layout_index_from_channel(ichl, ch->in_channel);
+            if (ch->in_channel_idx < 0) {
+                av_channel_name(inbuf, sizeof(inbuf), ch->in_channel);
+                av_log(ctx, AV_LOG_ERROR, "Requested channel %s is not present in "
+                       "input stream #%d.\n", inbuf,
+                       ch->input);
+                ret = AVERROR(EINVAL);
+                goto fail;
+            }
+        }
 
-        if (!ch->in_channel)
-            ch->in_channel = av_channel_layout_extract_channel(inlink->channel_layout,
-                                                               ch->in_channel_idx);
-
-        if (!(ch->in_channel & inlink->channel_layout)) {
-            av_log(ctx, AV_LOG_ERROR, "Requested channel %s is not present in "
-                   "input stream #%d.\n", av_get_channel_name(ch->in_channel),
-                   ch->input);
+        /* make sure channels specified by index actually exist */
+        if (ch->in_channel_idx >= ichl->nb_channels) {
+            av_log(ctx, AV_LOG_ERROR, "Requested channel with index %d is not "
+                   "present in input stream #%d.\n", ch->in_channel_idx, ch->input);
             ret = AVERROR(EINVAL);
             goto fail;
         }
 
-        inputs[ch->input] |= ch->in_channel;
+        channel_list_pop_ch(iu, av_channel_layout_channel_from_index(ichl, ch->in_channel_idx));
     }
 
     /* guess channel maps when not explicitly defined */
     /* first try unused matching channels */
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
 
         if (ch->input < 0)
-            guess_map_matching(ctx, ch, inputs);
+            guess_map_matching(ctx, ch, inputs_unused);
     }
 
     /* if the above failed, try to find _any_ unused input channel */
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
 
         if (ch->input < 0)
-            guess_map_any(ctx, ch, inputs);
+            guess_map_any(ctx, ch, inputs_unused);
 
         if (ch->input < 0) {
+            av_channel_name(outbuf, sizeof(outbuf), ch->out_channel);
             av_log(ctx, AV_LOG_ERROR, "Could not find input channel for "
                    "output channel '%s'.\n",
-                   av_get_channel_name(ch->out_channel));
+                   outbuf);
+            ret = AVERROR(EINVAL);
             goto fail;
         }
 
-        ch->in_channel_idx = av_get_channel_layout_channel_index(ctx->inputs[ch->input]->channel_layout,
-                                                                 ch->in_channel);
+        if (ch->in_channel != AV_CHAN_NONE) {
+            ch->in_channel_idx = av_channel_layout_index_from_channel(
+                &ctx->inputs[ch->input]->ch_layout, ch->in_channel);
+        }
+
+        av_assert0(ch->in_channel_idx >= 0);
     }
 
     /* print mappings */
     av_log(ctx, AV_LOG_VERBOSE, "mappings: ");
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
-        av_log(ctx, AV_LOG_VERBOSE, "%d.%s => %s ", ch->input,
-               av_get_channel_name(ch->in_channel),
-               av_get_channel_name(ch->out_channel));
+        AVFilterLink  *inlink = ctx->inputs[ch->input];
+        AVChannelLayout *ichl = &inlink->ch_layout;
+        enum AVChannel  in_ch = av_channel_layout_channel_from_index(
+                                    ichl, ch->in_channel_idx);
+
+        av_channel_name(inbuf, sizeof(inbuf), in_ch);
+        av_channel_name(outbuf, sizeof(outbuf), ch->out_channel);
+        av_log(ctx, AV_LOG_VERBOSE, "%d.%s(%d) => %s(%d) ", ch->input,
+               inbuf, ch->in_channel_idx,
+               outbuf, i);
     }
     av_log(ctx, AV_LOG_VERBOSE, "\n");
 
     for (i = 0; i < ctx->nb_inputs; i++) {
-        if (!inputs[i])
+        if (inputs_unused[i].nb_ch == ctx->inputs[i]->ch_layout.nb_channels)
             av_log(ctx, AV_LOG_WARNING, "No channels are used from input "
                    "stream %d.\n", i);
     }
 
 fail:
-    av_freep(&inputs);
+    for (i = 0; i < ctx->nb_inputs; i++)
+        av_freep(&inputs_unused[i].ch);
+    av_freep(&inputs_unused);
     return ret;
 }
 
@@ -382,8 +460,8 @@ static int try_push_frame(AVFilterContext *ctx)
     frame = av_frame_alloc();
     if (!frame)
         return AVERROR(ENOMEM);
-    if (s->nb_channels > FF_ARRAY_ELEMS(frame->data)) {
-        frame->extended_data = av_calloc(s->nb_channels,
+    if (s->ch_layout.nb_channels > FF_ARRAY_ELEMS(frame->data)) {
+        frame->extended_data = av_calloc(s->ch_layout.nb_channels,
                                           sizeof(*frame->extended_data));
         if (!frame->extended_data) {
             ret = AVERROR(ENOMEM);
@@ -392,7 +470,7 @@ static int try_push_frame(AVFilterContext *ctx)
     }
 
     /* copy the data pointers */
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
         AVFrame *cur   = s->input_frames[ch->input];
         AVBufferRef *buf;
@@ -442,7 +520,13 @@ static int try_push_frame(AVFilterContext *ctx)
     }
 
     frame->nb_samples     = nb_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     frame->channel_layout = outlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&frame->ch_layout, &outlink->ch_layout)) < 0)
+        return ret;
     frame->channels       = outlink->channels;
     frame->sample_rate    = outlink->sample_rate;
     frame->format         = outlink->format;
@@ -450,7 +534,7 @@ static int try_push_frame(AVFilterContext *ctx)
     frame->linesize[0]    = linesize;
     if (frame->data != frame->extended_data) {
         memcpy(frame->data, frame->extended_data, sizeof(*frame->data) *
-               FFMIN(FF_ARRAY_ELEMS(frame->data), s->nb_channels));
+               FFMIN(FF_ARRAY_ELEMS(frame->data), s->ch_layout.nb_channels));
     }
 
     s->eof_pts = frame->pts + av_rescale_q(frame->nb_samples,
diff --git a/libavfilter/af_ladspa.c b/libavfilter/af_ladspa.c
index ff16388a56..2cf3d9741e 100644
--- a/libavfilter/af_ladspa.c
+++ b/libavfilter/af_ladspa.c
@@ -366,7 +366,13 @@ static int config_output(AVFilterLink *outlink)
         outlink->format      = inlink->format;
         outlink->sample_rate = inlink->sample_rate;
         if (s->nb_inputs == s->nb_outputs) {
+            if ((ret = av_channel_layout_copy(&outlink->ch_layout, &inlink->ch_layout)) < 0)
+                return ret;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             outlink->channel_layout = inlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             outlink->channels = inlink->channels;
         }
 
@@ -681,7 +687,7 @@ static int query_formats(AVFilterContext *ctx)
             return ret;
     } else if (s->nb_inputs == 2 && s->nb_outputs == 2) {
         layouts = NULL;
-        ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO);
+        ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
         if (ret < 0)
             return ret;
         ret = ff_set_common_channel_layouts(ctx, layouts);
@@ -692,10 +698,10 @@ static int query_formats(AVFilterContext *ctx)
 
         if (s->nb_inputs >= 1) {
             AVFilterLink *inlink = ctx->inputs[0];
-            uint64_t inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
+            AVChannelLayout inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
 
             layouts = NULL;
-            ret = ff_add_channel_layout(&layouts, inlayout);
+            ret = ff_add_channel_layout(&layouts, &inlayout);
             if (ret < 0)
                 return ret;
             ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts);
@@ -710,10 +716,10 @@ static int query_formats(AVFilterContext *ctx)
         }
 
         if (s->nb_outputs >= 1) {
-            uint64_t outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
+            AVChannelLayout outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
 
             layouts = NULL;
-            ret = ff_add_channel_layout(&layouts, outlayout);
+            ret = ff_add_channel_layout(&layouts, &outlayout);
             if (ret < 0)
                 return ret;
             ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts);
diff --git a/libavfilter/af_lv2.c b/libavfilter/af_lv2.c
index 0f0c797989..963818fb67 100644
--- a/libavfilter/af_lv2.c
+++ b/libavfilter/af_lv2.c
@@ -288,7 +288,14 @@ static int config_output(AVFilterLink *outlink)
         outlink->format      = inlink->format;
         outlink->sample_rate = sample_rate = inlink->sample_rate;
         if (s->nb_inputs == s->nb_outputs) {
+            int ret;
+            if ((ret = av_channel_layout_copy(&outlink->ch_layout, &inlink->ch_layout)) < 0)
+                return ret;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             outlink->channel_layout = inlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             outlink->channels = inlink->channels;
         }
 
@@ -496,7 +503,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if (s->nb_inputs == 2 && s->nb_outputs == 2) {
         layouts = NULL;
-        ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO);
+        ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
         if (ret < 0)
             return ret;
         ret = ff_set_common_channel_layouts(ctx, layouts);
@@ -505,10 +512,10 @@ static int query_formats(AVFilterContext *ctx)
     } else {
         if (s->nb_inputs >= 1) {
             AVFilterLink *inlink = ctx->inputs[0];
-            uint64_t inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
+            AVChannelLayout inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
 
             layouts = NULL;
-            ret = ff_add_channel_layout(&layouts, inlayout);
+            ret = ff_add_channel_layout(&layouts, &inlayout);
             if (ret < 0)
                 return ret;
             ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts);
@@ -523,10 +530,10 @@ static int query_formats(AVFilterContext *ctx)
         }
 
         if (s->nb_outputs >= 1) {
-            uint64_t outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
+            AVChannelLayout outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
 
             layouts = NULL;
-            ret = ff_add_channel_layout(&layouts, outlayout);
+            ret = ff_add_channel_layout(&layouts, &outlayout);
             if (ret < 0)
                 return ret;
             ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts);
diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c
index a8a18960c4..424eca2664 100644
--- a/libavfilter/af_pan.c
+++ b/libavfilter/af_pan.c
@@ -42,7 +42,7 @@
 typedef struct PanContext {
     const AVClass *class;
     char *args;
-    int64_t out_channel_layout;
+    AVChannelLayout out_channel_layout;
     double gain[MAX_CHANNELS][MAX_CHANNELS];
     int64_t need_renorm;
     int need_renumber;
@@ -65,23 +65,15 @@ static void skip_spaces(char **arg)
 static int parse_channel_name(char **arg, int *rchannel, int *rnamed)
 {
     char buf[8];
-    int len, i, channel_id = 0;
-    int64_t layout, layout0;
+    int len, channel_id = 0;
 
     skip_spaces(arg);
     /* try to parse a channel name, e.g. "FL" */
     if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
-        layout0 = layout = av_get_channel_layout(buf);
-        /* channel_id <- first set bit in layout */
-        for (i = 32; i > 0; i >>= 1) {
-            if (layout >= (int64_t)1 << i) {
-                channel_id += i;
-                layout >>= i;
-            }
-        }
-        /* reject layouts that are not a single channel */
-        if (channel_id >= MAX_CHANNELS || layout0 != (int64_t)1 << channel_id)
-            return AVERROR(EINVAL);
+        channel_id = av_channel_from_string(buf);
+        if (channel_id < 0)
+            return channel_id;
+
         *rchannel = channel_id;
         *rnamed = 1;
         *arg += len;
@@ -137,17 +129,12 @@ static av_cold int init(AVFilterContext *ctx)
             goto fail;
         }
         if (named) {
-            if (!((pan->out_channel_layout >> out_ch_id) & 1)) {
+            if ((out_ch_id = av_channel_layout_index_from_channel(&pan->out_channel_layout, out_ch_id)) < 0) {
                 av_log(ctx, AV_LOG_ERROR,
                        "Channel \"%.8s\" does not exist in the chosen layout\n", arg0);
                 ret = AVERROR(EINVAL);
                 goto fail;
             }
-            /* get the channel number in the output channel layout:
-             * out_channel_layout & ((1 << out_ch_id) - 1) are all the
-             * channels that come before out_ch_id,
-             * so their count is the index of out_ch_id */
-            out_ch_id = av_get_channel_layout_nb_channels(pan->out_channel_layout & (((int64_t)1 << out_ch_id) - 1));
         }
         if (out_ch_id < 0 || out_ch_id >= pan->nb_output_channels) {
             av_log(ctx, AV_LOG_ERROR,
@@ -269,9 +256,7 @@ static int query_formats(AVFilterContext *ctx)
 
     // outlink supports only requested output channel layout
     layouts = NULL;
-    if ((ret = ff_add_channel_layout(&layouts,
-                          pan->out_channel_layout ? pan->out_channel_layout :
-                          FF_COUNT2LAYOUT(pan->nb_output_channels))) < 0)
+    if ((ret = ff_add_channel_layout(&layouts, &pan->out_channel_layout)) < 0)
         return ret;
     return ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts);
 }
@@ -281,13 +266,13 @@ static int config_props(AVFilterLink *link)
     AVFilterContext *ctx = link->dst;
     PanContext *pan = ctx->priv;
     char buf[1024], *cur;
-    int i, j, k, r;
+    int i, j, k, r, ret;
     double t;
 
     if (pan->need_renumber) {
         // input channels were given by their name: renumber them
         for (i = j = 0; i < MAX_CHANNELS; i++) {
-            if ((link->channel_layout >> i) & 1) {
+            if (av_channel_layout_index_from_channel(&link->ch_layout, i) >= 0) {
                 for (k = 0; k < pan->nb_output_channels; k++)
                     pan->gain[k][j] = pan->gain[k][i];
                 j++;
@@ -306,20 +291,12 @@ static int config_props(AVFilterLink *link)
     }
 
     // init libswresample context
-    pan->swr = swr_alloc_set_opts(pan->swr,
-                                  pan->out_channel_layout, link->format, link->sample_rate,
-                                  link->channel_layout,    link->format, link->sample_rate,
-                                  0, ctx);
-    if (!pan->swr)
+    ret = swr_alloc_set_opts2(&pan->swr,
+                              &pan->out_channel_layout, link->format, link->sample_rate,
+                              &link->ch_layout, link->format, link->sample_rate,
+                              0, ctx);
+    if (ret < 0)
         return AVERROR(ENOMEM);
-    if (!link->channel_layout) {
-        if (av_opt_set_int(pan->swr, "ich", link->channels, 0) < 0)
-            return AVERROR(EINVAL);
-    }
-    if (!pan->out_channel_layout) {
-        if (av_opt_set_int(pan->swr, "och", pan->nb_output_channels, 0) < 0)
-            return AVERROR(EINVAL);
-    }
 
     // gains are pure, init the channel mapping
     if (pan->pure_gains) {
@@ -336,7 +313,6 @@ static int config_props(AVFilterLink *link)
             pan->channel_map[i] = ch_id;
         }
 
-        av_opt_set_int(pan->swr, "icl", pan->out_channel_layout, 0);
         av_opt_set_int(pan->swr, "uch", pan->nb_output_channels, 0);
         swr_set_channel_mapping(pan->swr, pan->channel_map);
     } else {
@@ -357,8 +333,6 @@ static int config_props(AVFilterLink *link)
             for (j = 0; j < link->channels; j++)
                 pan->gain[i][j] /= t;
         }
-        av_opt_set_int(pan->swr, "icl", link->channel_layout, 0);
-        av_opt_set_int(pan->swr, "ocl", pan->out_channel_layout, 0);
         swr_set_matrix(pan->swr, pan->gain[0], pan->gain[1] - pan->gain[0]);
     }
 
@@ -405,7 +379,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
     swr_convert(pan->swr, outsamples->extended_data, n,
                 (void *)insamples->extended_data, n);
     av_frame_copy_props(outsamples, insamples);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     outsamples->channel_layout = outlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&outsamples->ch_layout, &outlink->ch_layout)) < 0)
+        return ret;
     outsamples->channels = outlink->channels;
 
     ret = ff_filter_frame(outlink, outsamples);
diff --git a/libavfilter/af_replaygain.c b/libavfilter/af_replaygain.c
index e9bfc5676c..53852ac8bc 100644
--- a/libavfilter/af_replaygain.c
+++ b/libavfilter/af_replaygain.c
@@ -327,7 +327,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_sofalizer.c b/libavfilter/af_sofalizer.c
index 20b717bdf8..383d137144 100644
--- a/libavfilter/af_sofalizer.c
+++ b/libavfilter/af_sofalizer.c
@@ -187,25 +187,15 @@ static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
 
 static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
 {
-    int len, i, channel_id = 0;
-    int64_t layout, layout0;
+    int len, channel_id = 0;
     char buf[8] = {0};
 
     /* try to parse a channel name, e.g. "FL" */
     if (av_sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
-        layout0 = layout = av_get_channel_layout(buf);
-        /* channel_id <- first set bit in layout */
-        for (i = 32; i > 0; i >>= 1) {
-            if (layout >= 1LL << i) {
-                channel_id += i;
-                layout >>= i;
-            }
-        }
-        /* reject layouts that are not a single channel */
-        if (channel_id >= 64 || layout0 != 1LL << channel_id) {
-            av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf);
-            return AVERROR(EINVAL);
-        }
+        channel_id = av_channel_from_string(buf);
+        if (channel_id < 0)
+            return channel_id;
+
         *rchannel = channel_id;
         *arg += len;
         return 0;
@@ -221,7 +211,7 @@ static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
     return AVERROR(EINVAL);
 }
 
-static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout)
+static void parse_speaker_pos(AVFilterContext *ctx)
 {
     SOFAlizerContext *s = ctx->priv;
     char *arg, *tokenizer, *p, *args = av_strdup(s->speakers_pos);
@@ -256,7 +246,7 @@ static int get_speaker_pos(AVFilterContext *ctx,
                            float *speaker_azim, float *speaker_elev)
 {
     struct SOFAlizerContext *s = ctx->priv;
-    uint64_t channels_layout = ctx->inputs[0]->channel_layout;
+    AVChannelLayout *channel_layout = &ctx->inputs[0]->ch_layout;
     float azim[64] = { 0 };
     float elev[64] = { 0 };
     int m, ch, n_conv = ctx->inputs[0]->channels; /* get no. input channels */
@@ -267,45 +257,45 @@ static int get_speaker_pos(AVFilterContext *ctx,
     s->lfe_channel = -1;
 
     if (s->speakers_pos)
-        parse_speaker_pos(ctx, channels_layout);
+        parse_speaker_pos(ctx);
 
     /* set speaker positions according to input channel configuration: */
     for (m = 0, ch = 0; ch < n_conv && m < 64; m++) {
-        uint64_t mask = channels_layout & (1ULL << m);
-
-        switch (mask) {
-        case AV_CH_FRONT_LEFT:            azim[ch] =  30;      break;
-        case AV_CH_FRONT_RIGHT:           azim[ch] = 330;      break;
-        case AV_CH_FRONT_CENTER:          azim[ch] =   0;      break;
-        case AV_CH_LOW_FREQUENCY:
-        case AV_CH_LOW_FREQUENCY_2:       s->lfe_channel = ch; break;
-        case AV_CH_BACK_LEFT:             azim[ch] = 150;      break;
-        case AV_CH_BACK_RIGHT:            azim[ch] = 210;      break;
-        case AV_CH_BACK_CENTER:           azim[ch] = 180;      break;
-        case AV_CH_SIDE_LEFT:             azim[ch] =  90;      break;
-        case AV_CH_SIDE_RIGHT:            azim[ch] = 270;      break;
-        case AV_CH_FRONT_LEFT_OF_CENTER:  azim[ch] =  15;      break;
-        case AV_CH_FRONT_RIGHT_OF_CENTER: azim[ch] = 345;      break;
-        case AV_CH_TOP_CENTER:            azim[ch] =   0;
+        int chan = av_channel_layout_channel_from_index(channel_layout, m);
+
+        switch (chan) {
+        case AV_CHAN_FRONT_LEFT:          azim[ch] =  30;      break;
+        case AV_CHAN_FRONT_RIGHT:         azim[ch] = 330;      break;
+        case AV_CHAN_FRONT_CENTER:        azim[ch] =   0;      break;
+        case AV_CHAN_LOW_FREQUENCY:
+        case AV_CHAN_LOW_FREQUENCY_2:     s->lfe_channel = ch; break;
+        case AV_CHAN_BACK_LEFT:           azim[ch] = 150;      break;
+        case AV_CHAN_BACK_RIGHT:          azim[ch] = 210;      break;
+        case AV_CHAN_BACK_CENTER:         azim[ch] = 180;      break;
+        case AV_CHAN_SIDE_LEFT:           azim[ch] =  90;      break;
+        case AV_CHAN_SIDE_RIGHT:          azim[ch] = 270;      break;
+        case AV_CHAN_FRONT_LEFT_OF_CENTER:  azim[ch] =  15;    break;
+        case AV_CHAN_FRONT_RIGHT_OF_CENTER: azim[ch] = 345;    break;
+        case AV_CHAN_TOP_CENTER:          azim[ch] =   0;
                                           elev[ch] =  90;      break;
-        case AV_CH_TOP_FRONT_LEFT:        azim[ch] =  30;
+        case AV_CHAN_TOP_FRONT_LEFT:      azim[ch] =  30;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_FRONT_CENTER:      azim[ch] =   0;
+        case AV_CHAN_TOP_FRONT_CENTER:    azim[ch] =   0;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_FRONT_RIGHT:       azim[ch] = 330;
+        case AV_CHAN_TOP_FRONT_RIGHT:     azim[ch] = 330;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_BACK_LEFT:         azim[ch] = 150;
+        case AV_CHAN_TOP_BACK_LEFT:       azim[ch] = 150;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_BACK_RIGHT:        azim[ch] = 210;
+        case AV_CHAN_TOP_BACK_RIGHT:      azim[ch] = 210;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_BACK_CENTER:       azim[ch] = 180;
+        case AV_CHAN_TOP_BACK_CENTER:     azim[ch] = 180;
                                           elev[ch] =  45;      break;
-        case AV_CH_WIDE_LEFT:             azim[ch] =  90;      break;
-        case AV_CH_WIDE_RIGHT:            azim[ch] = 270;      break;
-        case AV_CH_SURROUND_DIRECT_LEFT:  azim[ch] =  90;      break;
-        case AV_CH_SURROUND_DIRECT_RIGHT: azim[ch] = 270;      break;
-        case AV_CH_STEREO_LEFT:           azim[ch] =  90;      break;
-        case AV_CH_STEREO_RIGHT:          azim[ch] = 270;      break;
+        case AV_CHAN_WIDE_LEFT:           azim[ch] =  90;      break;
+        case AV_CHAN_WIDE_RIGHT:          azim[ch] = 270;      break;
+        case AV_CHAN_SURROUND_DIRECT_LEFT:  azim[ch] =  90;    break;
+        case AV_CHAN_SURROUND_DIRECT_RIGHT: azim[ch] = 270;    break;
+        case AV_CHAN_STEREO_LEFT:         azim[ch] =  90;      break;
+        case AV_CHAN_STEREO_RIGHT:        azim[ch] = 270;      break;
         case 0:                                                break;
         default:
             return AVERROR(EINVAL);
@@ -316,7 +306,7 @@ static int get_speaker_pos(AVFilterContext *ctx,
             elev[ch] = s->vspkrpos[m].elev;
         }
 
-        if (mask)
+        if (chan)
             ch++;
     }
 
@@ -668,7 +658,7 @@ static int query_formats(AVFilterContext *ctx)
         return ret;
 
     layouts = NULL;
-    ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO);
+    ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
     if (ret)
         return ret;
 
diff --git a/libavfilter/af_speechnorm.c b/libavfilter/af_speechnorm.c
index 212a926f36..3b20f61d99 100644
--- a/libavfilter/af_speechnorm.c
+++ b/libavfilter/af_speechnorm.c
@@ -68,7 +68,7 @@ typedef struct SpeechNormalizerContext {
     double threshold_value;
     double raise_amount;
     double fall_amount;
-    uint64_t channels;
+    AVChannelLayout ch_layout;
     int invert;
     int link;
 
@@ -103,8 +103,8 @@ static const AVOption speechnorm_options[] = {
     { "r",     "set the expansion raising amount", OFFSET(raise_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS },
     { "fall", "set the compression raising amount", OFFSET(fall_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS },
     { "f",    "set the compression raising amount", OFFSET(fall_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS },
-    { "channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS },
-    { "h",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS },
+    { "channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS },
+    { "h",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS },
     { "invert", "set inverted filtering", OFFSET(invert), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
     { "i",      "set inverted filtering", OFFSET(invert), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
     { "link", "set linked channels filtering", OFFSET(link), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
@@ -287,7 +287,8 @@ static void filter_channels_## name (AVFilterContext *ctx,
         ChannelContext *cc = &s->cc[ch];                                        \
         const ptype *src = (const ptype *)in->extended_data[ch];                \
         ptype *dst = (ptype *)out->extended_data[ch];                           \
-        const int bypass = !(av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels); \
+        const int bypass = !(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 && \
+                             av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0); \
         int n = 0;                                                              \
                                                                                 \
         while (n < nb_samples) {                                                \
@@ -336,7 +337,8 @@ static void filter_link_channels_## name (AVFilterContext *ctx,
         for (int ch = 0; ch < inlink->channels; ch++) {                         \
             ChannelContext *cc = &s->cc[ch];                                    \
                                                                                 \
-            cc->bypass = !(av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels); \
+            cc->bypass = !(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 && \
+                             av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0); \
                                                                                 \
             next_pi(ctx, cc, cc->bypass);                                       \
             min_size = FFMIN(min_size, cc->pi_size);                            \
diff --git a/libavfilter/af_stereotools.c b/libavfilter/af_stereotools.c
index 27ec4a2e4a..eedc7c68bd 100644
--- a/libavfilter/af_stereotools.c
+++ b/libavfilter/af_stereotools.c
@@ -107,7 +107,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_stereowiden.c b/libavfilter/af_stereowiden.c
index 7cce1a8f28..a91ea03957 100644
--- a/libavfilter/af_stereowiden.c
+++ b/libavfilter/af_stereowiden.c
@@ -60,7 +60,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_surround.c b/libavfilter/af_surround.c
index ccd85148e9..a5fa595d20 100644
--- a/libavfilter/af_surround.c
+++ b/libavfilter/af_surround.c
@@ -92,8 +92,8 @@ typedef struct AudioSurroundContext {
     float lowcut;
     float highcut;
 
-    uint64_t out_channel_layout;
-    uint64_t in_channel_layout;
+    AVChannelLayout out_channel_layout;
+    AVChannelLayout in_channel_layout;
     int nb_in_channels;
     int nb_out_channels;
 
@@ -171,7 +171,7 @@ static int query_formats(AVFilterContext *ctx)
         return ret;
 
     layouts = NULL;
-    ret = ff_add_channel_layout(&layouts, s->out_channel_layout);
+    ret = ff_add_channel_layout(&layouts, &s->out_channel_layout);
     if (ret)
         return ret;
 
@@ -180,7 +180,7 @@ static int query_formats(AVFilterContext *ctx)
         return ret;
 
     layouts = NULL;
-    ret = ff_add_channel_layout(&layouts, s->in_channel_layout);
+    ret = ff_add_channel_layout(&layouts, &s->in_channel_layout);
     if (ret)
         return ret;
 
@@ -212,31 +212,31 @@ static int config_input(AVFilterLink *inlink)
         return AVERROR(ENOMEM);
     for (ch = 0;  ch < s->nb_in_channels; ch++)
         s->input_levels[ch] = s->level_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_CENTER);
     if (ch >= 0)
         s->input_levels[ch] *= s->fc_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_LEFT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_LEFT);
     if (ch >= 0)
         s->input_levels[ch] *= s->fl_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_RIGHT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_RIGHT);
     if (ch >= 0)
         s->input_levels[ch] *= s->fr_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_LEFT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_LEFT);
     if (ch >= 0)
         s->input_levels[ch] *= s->sl_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_RIGHT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_RIGHT);
     if (ch >= 0)
         s->input_levels[ch] *= s->sr_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_LEFT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_LEFT);
     if (ch >= 0)
         s->input_levels[ch] *= s->bl_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_RIGHT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_RIGHT);
     if (ch >= 0)
         s->input_levels[ch] *= s->br_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_CENTER);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_CENTER);
     if (ch >= 0)
         s->input_levels[ch] *= s->bc_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_LOW_FREQUENCY);
     if (ch >= 0)
         s->input_levels[ch] *= s->lfe_in;
 
@@ -275,31 +275,31 @@ static int config_output(AVFilterLink *outlink)
         return AVERROR(ENOMEM);
     for (ch = 0;  ch < s->nb_out_channels; ch++)
         s->output_levels[ch] = s->level_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_CENTER);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_CENTER);
     if (ch >= 0)
         s->output_levels[ch] *= s->fc_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_LEFT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_LEFT);
     if (ch >= 0)
         s->output_levels[ch] *= s->fl_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_RIGHT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_RIGHT);
     if (ch >= 0)
         s->output_levels[ch] *= s->fr_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_SIDE_LEFT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_SIDE_LEFT);
     if (ch >= 0)
         s->output_levels[ch] *= s->sl_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_SIDE_RIGHT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_SIDE_RIGHT);
     if (ch >= 0)
         s->output_levels[ch] *= s->sr_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_LEFT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_LEFT);
     if (ch >= 0)
         s->output_levels[ch] *= s->bl_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_RIGHT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_RIGHT);
     if (ch >= 0)
         s->output_levels[ch] *= s->br_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_CENTER);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_CENTER);
     if (ch >= 0)
         s->output_levels[ch] *= s->bc_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_LOW_FREQUENCY);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_LOW_FREQUENCY);
     if (ch >= 0)
         s->output_levels[ch] *= s->lfe_out;
 
@@ -1373,15 +1373,16 @@ static av_cold int init(AVFilterContext *ctx)
 {
     AudioSurroundContext *s = ctx->priv;
     float overlap;
-    int i;
+    int64_t in_channel_layout, out_channel_layout;
+    int i, ret;
 
-    if (!(s->out_channel_layout = av_get_channel_layout(s->out_channel_layout_str))) {
+    if ((ret = av_channel_layout_from_string(&s->out_channel_layout, s->out_channel_layout_str)) < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
                s->out_channel_layout_str);
-        return AVERROR(EINVAL);
+        return ret;
     }
 
-    if (!(s->in_channel_layout = av_get_channel_layout(s->in_channel_layout_str))) {
+    if ((ret = av_channel_layout_from_string(&s->in_channel_layout, s->in_channel_layout_str)) < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n",
                s->in_channel_layout_str);
         return AVERROR(EINVAL);
@@ -1393,10 +1394,15 @@ static av_cold int init(AVFilterContext *ctx)
         return AVERROR(EINVAL);
     }
 
-    switch (s->in_channel_layout) {
+    in_channel_layout  = s->in_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                         s->in_channel_layout.u.mask : 0;
+    out_channel_layout = s->out_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                         s->out_channel_layout.u.mask : 0;
+
+    switch (in_channel_layout) {
     case AV_CH_LAYOUT_STEREO:
         s->filter = filter_stereo;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_MONO:
             s->upmix_stereo = upmix_1_0;
             break;
@@ -1442,7 +1448,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_2POINT1:
         s->filter = filter_2_1;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_5POINT1_BACK:
             s->upmix_2_1 = upmix_5_1_back_2_1;
             break;
@@ -1452,7 +1458,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_SURROUND:
         s->filter = filter_surround;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_3POINT1:
             s->upmix_3_0 = upmix_3_1_surround;
             break;
@@ -1465,7 +1471,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_5POINT0:
         s->filter = filter_5_0_side;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_7POINT1:
             s->upmix_5_0 = upmix_7_1_5_0_side;
             break;
@@ -1475,7 +1481,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_5POINT1:
         s->filter = filter_5_1_side;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_7POINT1:
             s->upmix_5_1 = upmix_7_1_5_1;
             break;
@@ -1485,7 +1491,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_5POINT1_BACK:
         s->filter = filter_5_1_back;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_7POINT1:
             s->upmix_5_1 = upmix_7_1_5_1;
             break;
diff --git a/libavfilter/asrc_afirsrc.c b/libavfilter/asrc_afirsrc.c
index 3612610e75..b3651d3862 100644
--- a/libavfilter/asrc_afirsrc.c
+++ b/libavfilter/asrc_afirsrc.c
@@ -109,7 +109,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 static av_cold int query_formats(AVFilterContext *ctx)
 {
     AudioFIRSourceContext *s = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { s->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = {
         AV_SAMPLE_FMT_FLT,
diff --git a/libavfilter/asrc_anoisesrc.c b/libavfilter/asrc_anoisesrc.c
index 8c834492fe..8e90a420ea 100644
--- a/libavfilter/asrc_anoisesrc.c
+++ b/libavfilter/asrc_anoisesrc.c
@@ -84,7 +84,7 @@ AVFILTER_DEFINE_CLASS(anoisesrc);
 static av_cold int query_formats(AVFilterContext *ctx)
 {
     ANoiseSrcContext *s = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { s->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = {
         AV_SAMPLE_FMT_DBL,
diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c
index 7ee2fa5a5d..17cbc5fb6c 100644
--- a/libavfilter/asrc_anullsrc.c
+++ b/libavfilter/asrc_anullsrc.c
@@ -37,8 +37,7 @@
 
 typedef struct ANullContext {
     const AVClass *class;
-    char   *channel_layout_str;
-    uint64_t channel_layout;
+    AVChannelLayout ch_layout;
     char   *sample_rate_str;
     int     sample_rate;
     int64_t duration;
@@ -50,8 +49,8 @@ typedef struct ANullContext {
 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
 static const AVOption anullsrc_options[]= {
-    { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
-    { "cl",             "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
+    { "channel_layout", "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS },
+    { "cl",             "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS },
     { "sample_rate",    "set sample rate",    OFFSET(sample_rate_str)   , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
     { "r",              "set sample rate",    OFFSET(sample_rate_str)   , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
     { "nb_samples",     "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, UINT16_MAX, FLAGS },
@@ -72,17 +71,13 @@ static av_cold int init(AVFilterContext *ctx)
                                      null->sample_rate_str, ctx)) < 0)
         return ret;
 
-    if ((ret = ff_parse_channel_layout(&null->channel_layout, NULL,
-                                        null->channel_layout_str, ctx)) < 0)
-        return ret;
-
     return 0;
 }
 
 static int query_formats(AVFilterContext *ctx)
 {
     ANullContext *null = ctx->priv;
-    int64_t chlayouts[] = { null->channel_layout, -1 };
+    const AVChannelLayout chlayouts[] = { null->ch_layout, { 0 } };
     int sample_rates[] = { null->sample_rate, -1 };
     int ret;
 
diff --git a/libavfilter/asrc_flite.c b/libavfilter/asrc_flite.c
index 17e7a5b9bc..5fab8086ba 100644
--- a/libavfilter/asrc_flite.c
+++ b/libavfilter/asrc_flite.c
@@ -225,11 +225,13 @@ static int query_formats(AVFilterContext *ctx)
     int ret;
 
     AVFilterChannelLayouts *chlayouts = NULL;
-    int64_t chlayout = av_get_default_channel_layout(flite->wave->num_channels);
     AVFilterFormats *sample_formats = NULL;
     AVFilterFormats *sample_rates = NULL;
+    AVChannelLayout chlayout = { 0 };
 
-    if ((ret = ff_add_channel_layout         (&chlayouts     , chlayout                )) < 0 ||
+    av_channel_layout_default(&chlayout, flite->wave->num_channels);
+
+    if ((ret = ff_add_channel_layout         (&chlayouts     , &chlayout               )) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx            , chlayouts               )) < 0 ||
         (ret = ff_add_format                 (&sample_formats, AV_SAMPLE_FMT_S16       )) < 0 ||
         (ret = ff_set_common_formats         (ctx            , sample_formats          )) < 0 ||
diff --git a/libavfilter/asrc_hilbert.c b/libavfilter/asrc_hilbert.c
index 82996c7362..6469ea2cda 100644
--- a/libavfilter/asrc_hilbert.c
+++ b/libavfilter/asrc_hilbert.c
@@ -77,7 +77,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 static av_cold int query_formats(AVFilterContext *ctx)
 {
     HilbertContext *s = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { s->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = {
         AV_SAMPLE_FMT_FLT,
diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index aaa81291a8..e4ae61c406 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -76,7 +76,7 @@ static int activate(AVFilterContext *ctx)
 static int query_formats(AVFilterContext *ctx)
 {
     SincContext *s = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { s->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT,
                                                        AV_SAMPLE_FMT_NONE };
diff --git a/libavfilter/asrc_sine.c b/libavfilter/asrc_sine.c
index c8995ae2c9..780070e205 100644
--- a/libavfilter/asrc_sine.c
+++ b/libavfilter/asrc_sine.c
@@ -180,7 +180,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 static av_cold int query_formats(AVFilterContext *ctx)
 {
     SineContext *sine = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { sine->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16,
                                                        AV_SAMPLE_FMT_NONE };
diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index cebc9709dd..34cb1d1ec8 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -40,9 +40,8 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
 {
     AVFrame *frame = NULL;
     int channels = link->channels;
-    int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
 
-    av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels);
+    av_assert0(channels == link->ch_layout.nb_channels);
 
     if (!link->frame_pool) {
         link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
@@ -77,7 +76,15 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
         return NULL;
 
     frame->nb_samples = nb_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     frame->channel_layout = link->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if (av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) {
+        av_frame_free(&frame);
+        return NULL;
+    }
     frame->sample_rate = link->sample_rate;
 
     av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format);
diff --git a/libavfilter/avf_aphasemeter.c b/libavfilter/avf_aphasemeter.c
index d9302cf867..eae584d17f 100644
--- a/libavfilter/avf_aphasemeter.c
+++ b/libavfilter/avf_aphasemeter.c
@@ -101,7 +101,7 @@ static int query_formats(AVFilterContext *ctx)
     formats = ff_make_format_list(sample_fmts);
     if ((ret = ff_formats_ref         (formats, &inlink->outcfg.formats        )) < 0 ||
         (ret = ff_formats_ref         (formats, &outlink->incfg.formats        )) < 0 ||
-        (ret = ff_add_channel_layout  (&layout, AV_CH_LAYOUT_STEREO         )) < 0 ||
+        (ret = ff_add_channel_layout  (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO )) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0)
         return ret;
diff --git a/libavfilter/avf_avectorscope.c b/libavfilter/avf_avectorscope.c
index ba392153f3..c1deaa1ea0 100644
--- a/libavfilter/avf_avectorscope.c
+++ b/libavfilter/avf_avectorscope.c
@@ -207,7 +207,7 @@ static int query_formats(AVFilterContext *ctx)
 
     formats = ff_make_format_list(sample_fmts);
     if ((ret = ff_formats_ref         (formats, &inlink->outcfg.formats        )) < 0 ||
-        (ret = ff_add_channel_layout  (&layout, AV_CH_LAYOUT_STEREO         )) < 0 ||
+        (ret = ff_add_channel_layout  (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0)
         return ret;
 
diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c
index 6f63574a8f..057a957a2a 100644
--- a/libavfilter/avf_showcqt.c
+++ b/libavfilter/avf_showcqt.c
@@ -1325,7 +1325,8 @@ static int query_formats(AVFilterContext *ctx)
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
         AV_PIX_FMT_YUV444P, AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
     };
-    static const int64_t channel_layouts[] = { AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO_DOWNMIX, -1 };
+    static const AVChannelLayout channel_layouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO,
+                                                       (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, { 0 } };
     int ret;
 
     /* set input audio formats */
diff --git a/libavfilter/avf_showspatial.c b/libavfilter/avf_showspatial.c
index 64e5204837..74357a9e1a 100644
--- a/libavfilter/avf_showspatial.c
+++ b/libavfilter/avf_showspatial.c
@@ -94,7 +94,7 @@ static int query_formats(AVFilterContext *ctx)
 
     formats = ff_make_format_list(sample_fmts);
     if ((ret = ff_formats_ref         (formats, &inlink->outcfg.formats        )) < 0 ||
-        (ret = ff_add_channel_layout  (&layout, AV_CH_LAYOUT_STEREO         )) < 0 ||
+        (ret = ff_add_channel_layout  (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0)
         return ret;
 
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 74d2dd758c..6e958f1b0a 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -738,8 +738,7 @@ static int draw_legend(AVFilterContext *ctx, int samples)
     uint8_t *dst;
     char chlayout_str[128];
 
-    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), inlink->channels,
-                                 inlink->channel_layout);
+    av_channel_layout_describe(&inlink->ch_layout, chlayout_str, sizeof(chlayout_str));
 
     text = av_asprintf("%d Hz | %s", inlink->sample_rate, chlayout_str);
     if (!text)
diff --git a/libavfilter/avf_showvolume.c b/libavfilter/avf_showvolume.c
index 401b65ca69..e8edd867d8 100644
--- a/libavfilter/avf_showvolume.c
+++ b/libavfilter/avf_showvolume.c
@@ -322,6 +322,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
     ShowVolumeContext *s = ctx->priv;
     const int step = s->step;
     int c, j, k, max_draw;
+    char channel_name[64];
     AVFrame *out;
 
     if (!s->out || s->out->width  != outlink->w ||
@@ -375,8 +376,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
             }
 
             if (s->h >= 8 && s->draw_text) {
-                const char *channel_name = av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c));
-                if (!channel_name)
+                int ret = av_channel_name(channel_name, sizeof(channel_name), av_channel_layout_channel_from_index(&insamples->ch_layout, c));
+                if (ret < 0)
                     continue;
                 drawtext(s->out, c * (s->h + s->b) + (s->h - 10) / 2, outlink->h - 35, channel_name, 1);
             }
@@ -411,8 +412,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
             }
 
             if (s->h >= 8 && s->draw_text) {
-                const char *channel_name = av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c));
-                if (!channel_name)
+                int ret = av_channel_name(channel_name, sizeof(channel_name), av_channel_layout_channel_from_index(&insamples->ch_layout, c));
+                if (ret < 0)
                     continue;
                 drawtext(s->out, 2, c * (s->h + s->b) + (s->h - 8) / 2, channel_name, 0);
             }
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..b502356b3f 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -204,6 +204,7 @@ void avfilter_link_free(AVFilterLink **link)
 
     ff_framequeue_free(&(*link)->fifo);
     ff_frame_pool_uninit((FFFramePool**)&(*link)->frame_pool);
+    av_channel_layout_uninit(&(*link)->ch_layout);
 
     av_freep(link);
 }
@@ -405,7 +406,7 @@ void ff_tlog_link(void *ctx, AVFilterLink *link, int end)
                 end ? "\n" : "");
     } else {
         char buf[128];
-        av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
+        av_channel_layout_describe(&link->ch_layout, buf, sizeof(buf));
 
         ff_tlog(ctx,
                 "link[%p r:%d cl:%s fmt:%s %s->%s]%s",
@@ -1040,7 +1041,17 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
             av_log(link->dst, AV_LOG_ERROR, "Channel count change is not supported\n");
             goto error;
         }
-        if (frame->channel_layout != link->channel_layout) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (frame->channel_layout && frame->channel_layout != link->channel_layout) {
+            av_log(link->dst, AV_LOG_ERROR, "Channel layout change is not supported\n");
+            goto error;
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+        if (av_channel_layout_check(&frame->ch_layout) && av_channel_layout_compare(&frame->ch_layout, &link->ch_layout)) {
+#else
+        if (av_channel_layout_compare(&frame->ch_layout, &link->ch_layout)) {
+#endif
             av_log(link->dst, AV_LOG_ERROR, "Channel layout change is not supported\n");
             goto error;
         }
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index b105dc3159..329eac5b01 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -543,7 +543,15 @@ struct AVFilterLink {
     int h;                      ///< agreed upon image height
     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
     /* These parameters apply only to audio */
-    uint64_t channel_layout;    ///< channel layout of current buffer (see libavutil/channel_layout.h)
+#if FF_API_OLD_CHANNEL_LAYOUT
+    /**
+     * channel layout of current buffer (see libavutil/channel_layout.h)
+     * @deprecated use ch_layout
+     */
+    attribute_deprecated
+    uint64_t channel_layout;
+#endif
+    AVChannelLayout ch_layout;    ///< channel layout of current buffer (see libavutil/channel_layout.h)
     int sample_rate;            ///< samples per second
 
     int format;                 ///< agreed upon media format
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b8b432e98b..08cc16b53a 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -639,6 +639,8 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
     link->format = link->incfg.formats->formats[0];
 
     if (link->type == AVMEDIA_TYPE_AUDIO) {
+        int ret;
+
         if (!link->incfg.samplerates->nb_formats) {
             av_log(link->src, AV_LOG_ERROR, "Cannot select sample rate for"
                    " the link between filters %s and %s.\n", link->src->name,
@@ -659,11 +661,16 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
             return AVERROR(EINVAL);
         }
         link->incfg.channel_layouts->nb_channel_layouts = 1;
-        link->channel_layout = link->incfg.channel_layouts->channel_layouts[0];
-        if ((link->channels = FF_LAYOUT2COUNT(link->channel_layout)))
-            link->channel_layout = 0;
-        else
-            link->channels = av_get_channel_layout_nb_channels(link->channel_layout);
+        ret = av_channel_layout_copy(&link->ch_layout, &link->incfg.channel_layouts->channel_layouts[0]);
+        if (ret < 0)
+            return ret;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        link->channel_layout = link->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                               link->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+        link->channels = link->ch_layout.nb_channels;
     }
 
     ff_formats_unref(&link->incfg.formats);
@@ -725,12 +732,12 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
     /* reduce channel layouts */
     for (i = 0; i < filter->nb_inputs; i++) {
         AVFilterLink *inlink = filter->inputs[i];
-        uint64_t fmt;
+        AVChannelLayout fmt = { 0 };
 
         if (!inlink->outcfg.channel_layouts ||
             inlink->outcfg.channel_layouts->nb_channel_layouts != 1)
             continue;
-        fmt = inlink->outcfg.channel_layouts->channel_layouts[0];
+        av_channel_layout_copy(&fmt, &inlink->outcfg.channel_layouts->channel_layouts[0]);
 
         for (j = 0; j < filter->nb_outputs; j++) {
             AVFilterLink *outlink = filter->outputs[j];
@@ -741,17 +748,17 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
                 continue;
 
             if (fmts->all_layouts &&
-                (!FF_LAYOUT2COUNT(fmt) || fmts->all_counts)) {
+                (KNOWN(&fmt) || fmts->all_counts)) {
                 /* Turn the infinite list into a singleton */
                 fmts->all_layouts = fmts->all_counts  = 0;
-                if (ff_add_channel_layout(&outlink->incfg.channel_layouts, fmt) < 0)
+                if (ff_add_channel_layout(&outlink->incfg.channel_layouts, &fmt) < 0)
                     ret = 1;
                 break;
             }
 
             for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) {
-                if (fmts->channel_layouts[k] == fmt) {
-                    fmts->channel_layouts[0]  = fmt;
+                if (!av_channel_layout_compare(&fmts->channel_layouts[k], &fmt)) {
+                    av_channel_layout_copy(&fmts->channel_layouts[0], &fmt);
                     fmts->nb_channel_layouts = 1;
                     ret = 1;
                     break;
@@ -887,26 +894,31 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter)
             continue;
 
         for (j = 0; j < outlink->incfg.channel_layouts->nb_channel_layouts; j++) {
-            uint64_t  in_chlayout = link->outcfg.channel_layouts->channel_layouts[0];
-            uint64_t out_chlayout = outlink->incfg.channel_layouts->channel_layouts[j];
-            int  in_channels      = av_get_channel_layout_nb_channels(in_chlayout);
-            int out_channels      = av_get_channel_layout_nb_channels(out_chlayout);
-            int count_diff        = out_channels - in_channels;
+            AVChannelLayout in_chlayout = { 0 }, out_chlayout = { 0 };
+            int  in_channels;
+            int out_channels;
+            int count_diff;
             int matched_channels, extra_channels;
             int score = 100000;
 
-            if (FF_LAYOUT2COUNT(in_chlayout) || FF_LAYOUT2COUNT(out_chlayout)) {
+            av_channel_layout_copy(&in_chlayout, &link->outcfg.channel_layouts->channel_layouts[0]);
+            av_channel_layout_copy(&out_chlayout, &outlink->incfg.channel_layouts->channel_layouts[j]);
+            in_channels            = in_chlayout.nb_channels;
+            out_channels           = out_chlayout.nb_channels;
+            count_diff             = out_channels - in_channels;
+            if (!KNOWN(&in_chlayout) || !KNOWN(&out_chlayout)) {
                 /* Compute score in case the input or output layout encodes
                    a channel count; in this case the score is not altered by
                    the computation afterwards, as in_chlayout and
                    out_chlayout have both been set to 0 */
-                if (FF_LAYOUT2COUNT(in_chlayout))
-                    in_channels = FF_LAYOUT2COUNT(in_chlayout);
-                if (FF_LAYOUT2COUNT(out_chlayout))
-                    out_channels = FF_LAYOUT2COUNT(out_chlayout);
+                if (!KNOWN(&in_chlayout))
+                    in_channels = FF_LAYOUT2COUNT(&in_chlayout);
+                if (!KNOWN(&out_chlayout))
+                    out_channels = FF_LAYOUT2COUNT(&out_chlayout);
                 score -= 10000 + FFABS(out_channels - in_channels) +
                          (in_channels > out_channels ? 10000 : 0);
-                in_chlayout = out_chlayout = 0;
+                av_channel_layout_uninit(&in_chlayout);
+                av_channel_layout_uninit(&out_chlayout);
                 /* Let the remaining computation run, even if the score
                    value is not altered */
             }
@@ -915,27 +927,27 @@ 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];
-                if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
-                    (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
-                    in_chlayout  &= ~cmp0;
-                    out_chlayout &= ~cmp1;
+                if ( av_channel_layout_subset(& in_chlayout, cmp0) &&
+                    !av_channel_layout_subset(&out_chlayout, cmp0) &&
+                     av_channel_layout_subset(&out_chlayout, cmp1) &&
+                    !av_channel_layout_subset(& in_chlayout, cmp1)) {
+                    av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(& in_chlayout, ~cmp0));
+                    av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&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_popcount64(cmp1) - 2;
                 }
             }
 
             /* no penalty for LFE channel mismatch */
-            if ( (in_chlayout & AV_CH_LOW_FREQUENCY) &&
-                (out_chlayout & AV_CH_LOW_FREQUENCY))
+            if (av_channel_layout_channel_from_index(&in_chlayout,  AV_CHAN_LOW_FREQUENCY) >= 0 &&
+                av_channel_layout_channel_from_index(&out_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0)
                 score += 10;
-            in_chlayout  &= ~AV_CH_LOW_FREQUENCY;
-            out_chlayout &= ~AV_CH_LOW_FREQUENCY;
+            av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(&in_chlayout, ~AV_CH_LOW_FREQUENCY));
+            av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~AV_CH_LOW_FREQUENCY));
 
-            matched_channels = av_get_channel_layout_nb_channels(in_chlayout &
-                                                                 out_chlayout);
-            extra_channels   = av_get_channel_layout_nb_channels(out_chlayout &
-                                                                 (~in_chlayout));
+            matched_channels = av_popcount64(in_chlayout.u.mask & out_chlayout.u.mask);
+            extra_channels   = av_popcount64(out_chlayout.u.mask & (~in_chlayout.u.mask));
             score += 10 * matched_channels - 5 * extra_channels;
 
             if (score > best_score ||
@@ -946,7 +958,7 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter)
             }
         }
         av_assert0(best_idx >= 0);
-        FFSWAP(uint64_t, outlink->incfg.channel_layouts->channel_layouts[0],
+        FFSWAP(AVChannelLayout, outlink->incfg.channel_layouts->channel_layouts[0],
                outlink->incfg.channel_layouts->channel_layouts[best_idx]);
     }
 
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index c0215669e7..b7fcaf89b2 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -74,7 +74,7 @@ static void cleanup_redundant_layouts(AVFilterContext *ctx)
         if (buf->channel_counts[i] < 64)
             counts |= (uint64_t)1 << buf->channel_counts[i];
     for (i = lc = 0; i < nb_layouts; i++) {
-        n = av_get_channel_layout_nb_channels(buf->channel_layouts[i]);
+        n = av_popcount64(buf->channel_layouts[i]);
         if (n < 64 && (counts & ((uint64_t)1 << n)))
             av_log(ctx, AV_LOG_WARNING,
                    "Removing channel layout 0x%"PRIx64", redundant with %d channels\n",
@@ -218,11 +218,28 @@ MAKE_AVFILTERLINK_ACCESSOR(int              , h                  )
 MAKE_AVFILTERLINK_ACCESSOR(AVRational       , sample_aspect_ratio)
 
 MAKE_AVFILTERLINK_ACCESSOR(int              , channels           )
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 MAKE_AVFILTERLINK_ACCESSOR(uint64_t         , channel_layout     )
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 MAKE_AVFILTERLINK_ACCESSOR(int              , sample_rate        )
 
 MAKE_AVFILTERLINK_ACCESSOR(AVBufferRef *    , hw_frames_ctx      )
 
+int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out)
+{
+    AVChannelLayout ch_layout = { 0 };
+    int ret;
+
+    av_assert0(ctx->filter->activate == activate);
+    ret = av_channel_layout_copy(&ch_layout, &ctx->inputs[0]->ch_layout);
+    if (ret < 0)
+        return ret;
+    *out = ch_layout;
+    return 0;
+}
+
 #define CHECK_LIST_SIZE(field) \
         if (buf->field ## _size % sizeof(*buf->field)) { \
             av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
@@ -256,6 +273,7 @@ static int asink_query_formats(AVFilterContext *ctx)
 {
     BufferSinkContext *buf = ctx->priv;
     AVFilterFormats *formats = NULL;
+    AVChannelLayout layout = { 0 };
     AVFilterChannelLayouts *layouts = NULL;
     unsigned i;
     int ret;
@@ -277,11 +295,14 @@ static int asink_query_formats(AVFilterContext *ctx)
         buf->all_channel_counts) {
         cleanup_redundant_layouts(ctx);
         for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
-            if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0)
+            if ((ret = av_channel_layout_from_mask(&layout, buf->channel_layouts[i])) < 0 ||
+                (ret = ff_add_channel_layout(&layouts, &layout) < 0))
                 return ret;
-        for (i = 0; i < NB_ITEMS(buf->channel_counts); i++)
-            if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0)
+        for (i = 0; i < NB_ITEMS(buf->channel_counts); i++) {
+            layout = FF_COUNT2LAYOUT(buf->channel_counts[i]);
+            if ((ret = ff_add_channel_layout(&layouts, &layout)) < 0)
                 return ret;
+        }
         if (buf->all_channel_counts) {
             if (layouts)
                 av_log(ctx, AV_LOG_WARNING,
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 69ed0f29a8..ae90ae87fa 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -46,7 +46,7 @@
  * - av_buffersink_get_h(),
  * - av_buffersink_get_sample_aspect_ratio(),
  * - av_buffersink_get_channels(),
- * - av_buffersink_get_channel_layout(),
+ * - av_buffersink_get_ch_layout(),
  * - av_buffersink_get_sample_rate().
  *
  * The format can be constrained by setting options, using av_opt_set() and
@@ -156,7 +156,12 @@ int              av_buffersink_get_h                   (const AVFilterContext *c
 AVRational       av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx);
 
 int              av_buffersink_get_channels            (const AVFilterContext *ctx);
+#if FF_API_OLD_CHANNEL_LAYOUT
+attribute_deprecated
 uint64_t         av_buffersink_get_channel_layout      (const AVFilterContext *ctx);
+#endif
+int              av_buffersink_get_ch_layout           (const AVFilterContext *ctx,
+                                                        AVChannelLayout *ch_layout);
 int              av_buffersink_get_sample_rate         (const AVFilterContext *ctx);
 
 AVBufferRef *    av_buffersink_get_hw_frames_ctx       (const AVFilterContext *ctx);
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index b0611872f1..0cfa6a9b3d 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -60,8 +60,8 @@ typedef struct BufferSourceContext {
     int sample_rate;
     enum AVSampleFormat sample_fmt;
     int channels;
-    uint64_t channel_layout;
     char    *channel_layout_str;
+    AVChannelLayout ch_layout;
 
     int eof;
 } BufferSourceContext;
@@ -73,12 +73,12 @@ typedef struct BufferSourceContext {
         av_log(s, AV_LOG_WARNING, "Changing video frame properties on the fly is not supported by all filters.\n");\
     }
 
-#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, ch_layout, ch_count, format, pts)\
+#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, layout, count, format, pts)\
     if (c->sample_fmt != format || c->sample_rate != srate ||\
-        c->channel_layout != ch_layout || c->channels != ch_count) {\
+        av_channel_layout_compare(&c->ch_layout, &layout) || c->channels != count) {\
         av_log(s, AV_LOG_INFO, "filter context - fmt: %s r: %d layout: %"PRIX64" ch: %d, incoming frame - fmt: %s r: %d layout: %"PRIX64" ch: %d pts_time: %s\n",\
-               av_get_sample_fmt_name(c->sample_fmt), c->sample_rate, c->channel_layout, c->channels,\
-               av_get_sample_fmt_name(format), srate, ch_layout, ch_count, av_ts2timestr(pts, &s->outputs[0]->time_base));\
+               av_get_sample_fmt_name(c->sample_fmt), c->sample_rate, c->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? c->ch_layout.u.mask : 0, c->channels,\
+               av_get_sample_fmt_name(format), srate, layout.order == AV_CHANNEL_ORDER_NATIVE ? layout.u.mask : 0, count, av_ts2timestr(pts, &s->outputs[0]->time_base));\
         av_log(s, AV_LOG_ERROR, "Changing audio frame properties on the fly is not supported.\n");\
         return AVERROR(EINVAL);\
     }
@@ -127,8 +127,20 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par
         }
         if (param->sample_rate > 0)
             s->sample_rate = param->sample_rate;
-        if (param->channel_layout)
-            s->channel_layout = param->channel_layout;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        // if the old/new fields are set inconsistently, prefer the old ones
+        if (param->channel_layout && (param->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
+                                      param->ch_layout.u.mask != param->channel_layout)) {
+            av_channel_layout_from_mask(&s->ch_layout, param->channel_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+        } else
+#endif
+        if (param->ch_layout.nb_channels) {
+            int ret = av_channel_layout_copy(&s->ch_layout, &param->ch_layout);
+            if (ret < 0)
+                return ret;
+        }
         break;
     default:
         return AVERROR_BUG;
@@ -168,11 +180,15 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra
     AVFrame *copy;
     int refcounted, ret;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     if (frame && frame->channel_layout &&
         av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) {
         av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
         return AVERROR(EINVAL);
     }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     s->nb_failed_requests = 0;
 
@@ -192,9 +208,19 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra
             break;
         case AVMEDIA_TYPE_AUDIO:
             /* For layouts unknown on input but known on link after negotiation. */
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             if (!frame->channel_layout)
-                frame->channel_layout = s->channel_layout;
-            CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->channel_layout,
+                frame->channel_layout = s->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                        s->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+            if (!frame->ch_layout.nb_channels) {
+                ret = av_channel_layout_copy(&frame->ch_layout, &s->ch_layout);
+                if (ret < 0)
+                    return ret;
+            }
+            CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->ch_layout,
                                      frame->channels, frame->format, frame->pts);
             break;
         default:
@@ -301,6 +327,7 @@ AVFILTER_DEFINE_CLASS(abuffer);
 static av_cold int init_audio(AVFilterContext *ctx)
 {
     BufferSourceContext *s = ctx->priv;
+    char buf[128];
     int ret = 0;
 
     if (s->sample_fmt == AV_SAMPLE_FMT_NONE) {
@@ -308,24 +335,39 @@ static av_cold int init_audio(AVFilterContext *ctx)
         return AVERROR(EINVAL);
     }
 
-    if (s->channel_layout_str || s->channel_layout) {
+    if (s->channel_layout_str || s->ch_layout.nb_channels) {
         int n;
 
-        if (!s->channel_layout) {
-            s->channel_layout = av_get_channel_layout(s->channel_layout_str);
-            if (!s->channel_layout) {
-                av_log(ctx, AV_LOG_ERROR, "Invalid channel layout %s.\n",
+        if (!s->ch_layout.nb_channels) {
+            ret = av_channel_layout_from_string(&s->ch_layout, s->channel_layout_str);
+            if (ret < 0) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+                uint64_t mask;
+FF_DISABLE_DEPRECATION_WARNINGS
+                mask = av_get_channel_layout(s->channel_layout_str);
+                if (!mask) {
+#endif
+                    av_log(ctx, AV_LOG_ERROR, "Invalid channel layout %s.\n",
+                           s->channel_layout_str);
+                    return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+                }
+FF_ENABLE_DEPRECATION_WARNINGS
+                av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
                        s->channel_layout_str);
-                return AVERROR(EINVAL);
+                av_channel_layout_from_mask(&s->ch_layout, mask);
+#endif
             }
         }
-        n = av_get_channel_layout_nb_channels(s->channel_layout);
+
+        n = s->ch_layout.nb_channels;
+        av_channel_layout_describe(&s->ch_layout, buf, sizeof(buf));
         if (s->channels) {
             if (n != s->channels) {
                 av_log(ctx, AV_LOG_ERROR,
                        "Mismatching channel count %d and layout '%s' "
                        "(%d channels)\n",
-                       s->channels, s->channel_layout_str, n);
+                       s->channels, buf, n);
                 return AVERROR(EINVAL);
             }
         }
@@ -334,6 +376,9 @@ static av_cold int init_audio(AVFilterContext *ctx)
         av_log(ctx, AV_LOG_ERROR, "Neither number of channels nor "
                                   "channel layout specified\n");
         return AVERROR(EINVAL);
+    } else {
+        s->ch_layout = FF_COUNT2LAYOUT(s->channels);
+        av_channel_layout_describe(&s->ch_layout, buf, sizeof(buf));
     }
 
     if (!s->time_base.num)
@@ -342,7 +387,7 @@ static av_cold int init_audio(AVFilterContext *ctx)
     av_log(ctx, AV_LOG_VERBOSE,
            "tb:%d/%d samplefmt:%s samplerate:%d chlayout:%s\n",
            s->time_base.num, s->time_base.den, av_get_sample_fmt_name(s->sample_fmt),
-           s->sample_rate, s->channel_layout_str);
+           s->sample_rate, buf);
 
     return ret;
 }
@@ -374,9 +419,7 @@ static int query_formats(AVFilterContext *ctx)
             (ret = ff_set_common_samplerates (ctx         , samplerates   )) < 0)
             return ret;
 
-        if ((ret = ff_add_channel_layout(&channel_layouts,
-                              c->channel_layout ? c->channel_layout :
-                              FF_COUNT2LAYOUT(c->channels))) < 0)
+        if ((ret = ff_add_channel_layout(&channel_layouts, &c->ch_layout)) < 0)
             return ret;
         if ((ret = ff_set_common_channel_layouts(ctx, channel_layouts)) < 0)
             return ret;
@@ -405,8 +448,11 @@ static int config_props(AVFilterLink *link)
         }
         break;
     case AVMEDIA_TYPE_AUDIO:
-        if (!c->channel_layout)
-            c->channel_layout = link->channel_layout;
+        if (!c->ch_layout.nb_channels) {
+            int ret = av_channel_layout_copy(&c->ch_layout, &link->ch_layout);
+            if (ret < 0)
+                return ret;
+        }
         break;
     default:
         return AVERROR(EINVAL);
diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index 08fbd18a47..3b248b37cd 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -110,10 +110,19 @@ typedef struct AVBufferSrcParameters {
      */
     int sample_rate;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
     /**
      * Audio only, the audio channel layout
+     * @deprecated use ch_layout
      */
+    attribute_deprecated
     uint64_t channel_layout;
+#endif
+
+    /**
+     * Audio only, the audio channel layout
+     */
+    AVChannelLayout ch_layout;
 } AVBufferSrcParameters;
 
 /**
diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c
index 88d6a1fe46..2a6edba3d8 100644
--- a/libavfilter/f_ebur128.c
+++ b/libavfilter/f_ebur128.c
@@ -422,7 +422,7 @@ static int config_audio_output(AVFilterLink *outlink)
     int i;
     AVFilterContext *ctx = outlink->src;
     EBUR128Context *ebur128 = ctx->priv;
-    const int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
+    const int nb_channels = outlink->ch_layout.nb_channels;
 
 #define BACK_MASK (AV_CH_BACK_LEFT    |AV_CH_BACK_CENTER    |AV_CH_BACK_RIGHT| \
                    AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT| \
@@ -439,8 +439,8 @@ static int config_audio_output(AVFilterLink *outlink)
 
     for (i = 0; i < nb_channels; i++) {
         /* channel weighting */
-        const uint64_t chl = av_channel_layout_extract_channel(outlink->channel_layout, i);
-        if (chl & (AV_CH_LOW_FREQUENCY|AV_CH_LOW_FREQUENCY_2)) {
+        const int chl = av_channel_layout_channel_from_index(&outlink->ch_layout, i);
+        if (chl == AV_CHAN_LOW_FREQUENCY || chl == AV_CHAN_LOW_FREQUENCY_2) {
             ebur128->ch_weighting[i] = 0;
         } else if (chl & BACK_MASK) {
             ebur128->ch_weighting[i] = 1.41;
@@ -472,11 +472,11 @@ static int config_audio_output(AVFilterLink *outlink)
             !ebur128->true_peaks_per_frame || !ebur128->swr_ctx)
             return AVERROR(ENOMEM);
 
-        av_opt_set_int(ebur128->swr_ctx, "in_channel_layout",    outlink->channel_layout, 0);
+        av_opt_set_chlayout(ebur128->swr_ctx, "in_ch_layout",   &outlink->ch_layout, 0);
         av_opt_set_int(ebur128->swr_ctx, "in_sample_rate",       outlink->sample_rate, 0);
         av_opt_set_sample_fmt(ebur128->swr_ctx, "in_sample_fmt", outlink->format, 0);
 
-        av_opt_set_int(ebur128->swr_ctx, "out_channel_layout",    outlink->channel_layout, 0);
+        av_opt_set_chlayout(ebur128->swr_ctx, "out_ch_layout",   &outlink->ch_layout, 0);
         av_opt_set_int(ebur128->swr_ctx, "out_sample_rate",       192000, 0);
         av_opt_set_sample_fmt(ebur128->swr_ctx, "out_sample_fmt", outlink->format, 0);
 
diff --git a/libavfilter/f_streamselect.c b/libavfilter/f_streamselect.c
index 3708d2b256..a895ddd4e0 100644
--- a/libavfilter/f_streamselect.c
+++ b/libavfilter/f_streamselect.c
@@ -119,7 +119,11 @@ static int config_output(AVFilterLink *outlink)
     case AVMEDIA_TYPE_AUDIO:
         outlink->sample_rate    = inlink->sample_rate;
         outlink->channels       = inlink->channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
         outlink->channel_layout = inlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         break;
     }
 
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index ba62f73248..8bf0fe2ef1 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -28,8 +28,6 @@
 #include "internal.h"
 #include "formats.h"
 
-#define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */
-
 /**
  * Add all refs from a to ret and destroy a.
  */
@@ -215,7 +213,7 @@ static int merge_channel_layouts(void *va, void *vb)
 {
     AVFilterChannelLayouts *a = va;
     AVFilterChannelLayouts *b = vb;
-    uint64_t *channel_layouts;
+    AVChannelLayout *channel_layouts;
     unsigned a_all = a->all_layouts + a->all_counts;
     unsigned b_all = b->all_layouts + b->all_counts;
     int ret_max, ret_nb = 0, i, j, round;
@@ -233,8 +231,8 @@ static int merge_channel_layouts(void *va, void *vb)
         if (a_all == 1 && !b_all) {
             /* keep only known layouts in b; works also for b_all = 1 */
             for (i = j = 0; i < b->nb_channel_layouts; i++)
-                if (KNOWN(b->channel_layouts[i]))
-                    b->channel_layouts[j++] = b->channel_layouts[i];
+                if (KNOWN(&b->channel_layouts[i]) && i != j++)
+                    av_channel_layout_copy(&b->channel_layouts[j], &b->channel_layouts[i]);
             /* Not optimal: the unknown layouts of b may become known after
                another merge. */
             if (!j)
@@ -246,17 +244,18 @@ static int merge_channel_layouts(void *va, void *vb)
     }
 
     ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
-    if (!(channel_layouts = av_malloc_array(ret_max, sizeof(*channel_layouts))))
+    if (!(channel_layouts = av_mallocz_array(ret_max, sizeof(*channel_layouts))))
         return AVERROR(ENOMEM);
 
     /* a[known] intersect b[known] */
     for (i = 0; i < a->nb_channel_layouts; i++) {
-        if (!KNOWN(a->channel_layouts[i]))
+        if (!KNOWN(&a->channel_layouts[i]))
             continue;
         for (j = 0; j < b->nb_channel_layouts; j++) {
-            if (a->channel_layouts[i] == b->channel_layouts[j]) {
-                channel_layouts[ret_nb++] = a->channel_layouts[i];
-                a->channel_layouts[i] = b->channel_layouts[j] = 0;
+            if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
+                av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
+                av_channel_layout_uninit(&a->channel_layouts[i]);
+                av_channel_layout_uninit(&b->channel_layouts[j]);
                 break;
             }
         }
@@ -265,24 +264,24 @@ static int merge_channel_layouts(void *va, void *vb)
        2nd round: a[generic] intersect b[known] */
     for (round = 0; round < 2; round++) {
         for (i = 0; i < a->nb_channel_layouts; i++) {
-            uint64_t fmt = a->channel_layouts[i], bfmt;
-            if (!fmt || !KNOWN(fmt))
+            AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 };
+            if (!av_channel_layout_check(fmt) || !KNOWN(fmt))
                 continue;
-            bfmt = FF_COUNT2LAYOUT(av_get_channel_layout_nb_channels(fmt));
+            bfmt = FF_COUNT2LAYOUT(fmt->nb_channels);
             for (j = 0; j < b->nb_channel_layouts; j++)
-                if (b->channel_layouts[j] == bfmt)
-                    channel_layouts[ret_nb++] = a->channel_layouts[i];
+                if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt))
+                    av_channel_layout_copy(&channel_layouts[ret_nb++], fmt);
         }
         /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
         FFSWAP(AVFilterChannelLayouts *, a, b);
     }
     /* a[generic] intersect b[generic] */
     for (i = 0; i < a->nb_channel_layouts; i++) {
-        if (KNOWN(a->channel_layouts[i]))
+        if (KNOWN(&a->channel_layouts[i]))
             continue;
         for (j = 0; j < b->nb_channel_layouts; j++)
-            if (a->channel_layouts[i] == b->channel_layouts[j])
-                channel_layouts[ret_nb++] = a->channel_layouts[i];
+            if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j]))
+                av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
     }
 
     if (!ret_nb) {
@@ -388,15 +387,31 @@ AVFilterFormats *ff_make_format_list(const int *fmts)
     return formats;
 }
 
-AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts)
+AVFilterChannelLayouts *ff_make_format64_list(const AVChannelLayout *fmts)
 {
-    MAKE_FORMAT_LIST(AVFilterChannelLayouts,
-                     channel_layouts, nb_channel_layouts);
+    AVFilterChannelLayouts *ch_layouts;
+    int count = 0;
+    if (fmts)
+        for (count = 0; fmts[count].nb_channels; count++)
+            ;
+    ch_layouts = av_mallocz(sizeof(*ch_layouts));
+    if (!ch_layouts)
+        return NULL;
+    ch_layouts->nb_channel_layouts = count;
+    if (count) {
+        ch_layouts->channel_layouts =
+            av_mallocz_array(count, sizeof(*ch_layouts->channel_layouts));
+        if (!ch_layouts->channel_layouts) {
+            av_freep(&ch_layouts);
+            return NULL;
+        }
+    }
+
     if (count)
-        memcpy(formats->channel_layouts, fmts,
-               sizeof(*formats->channel_layouts) * count);
+        memcpy(ch_layouts->channel_layouts, fmts,
+               sizeof(*ch_layouts->channel_layouts) * count);
 
-    return formats;
+    return ch_layouts;
 }
 
 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)        \
@@ -415,6 +430,11 @@ do {                                                        \
     }                                                       \
                                                             \
     (*f)->list = fmts;                                      \
+    ASSIGN_FMT(f, fmt, list, nb);                           \
+} while (0)
+
+#define ASSIGN_FMT(f, fmt, list, nb)                        \
+do {                                                        \
     (*f)->list[(*f)->nb++] = fmt;                           \
 } while (0)
 
@@ -424,10 +444,21 @@ int ff_add_format(AVFilterFormats **avff, int64_t fmt)
     return 0;
 }
 
-int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
+#undef ASSIGN_FMT
+#define ASSIGN_FMT(f, fmt, list, nb)                              \
+do {                                                              \
+    int ret;                                                      \
+    memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list));        \
+    ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt);     \
+    if (ret < 0)                                                  \
+        return ret;                                               \
+    (*f)->nb++;                                                   \
+} while (0)
+
+int ff_add_channel_layout(AVFilterChannelLayouts **l, AVChannelLayout *channel_layout)
 {
     av_assert1(!(*l && (*l)->all_layouts));
-    ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, uint64_t, channel_layouts, nb_channel_layouts);
+    ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
     return 0;
 }
 
@@ -664,7 +695,7 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx,
 }
 
 int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx,
-                                            const int64_t *fmts)
+                                            const AVChannelLayout *fmts)
 {
     return ff_set_common_channel_layouts(ctx, ff_make_format64_list(fmts));
 }
@@ -787,23 +818,41 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
     return 0;
 }
 
-int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
+int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
                             void *log_ctx)
 {
-    int64_t chlayout;
-    int nb_channels;
-
-    if (av_get_extended_channel_layout(arg, &chlayout, &nb_channels) < 0) {
-        av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
-        return AVERROR(EINVAL);
+    AVChannelLayout chlayout = { 0 };
+    int res;
+
+    res = av_channel_layout_from_string(&chlayout, arg);
+    if (res < 0) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+        int64_t mask;
+        int nb_channels;
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (av_get_extended_channel_layout(arg, &mask, &nb_channels) < 0) {
+#endif
+            av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
+            return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+        av_log(log_ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
+               arg);
+        if (mask)
+            av_channel_layout_from_mask(&chlayout, mask);
+        else
+            chlayout = (AVChannelLayout) { .order = AV_CHANNEL_ORDER_UNSPEC, .nb_channels = nb_channels };
+#endif
     }
-    if (!chlayout && !nret) {
+
+    if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) {
         av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
         return AVERROR(EINVAL);
     }
     *ret = chlayout;
     if (nret)
-        *nret = nb_channels;
+        *nret = chlayout.nb_channels;
 
     return 0;
 }
@@ -846,11 +895,11 @@ int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
     return check_list(log, "sample rate", fmts);
 }
 
-static int layouts_compatible(uint64_t a, uint64_t b)
+static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
 {
-    return a == b ||
-           (KNOWN(a) && !KNOWN(b) && av_get_channel_layout_nb_channels(a) == FF_LAYOUT2COUNT(b)) ||
-           (KNOWN(b) && !KNOWN(a) && av_get_channel_layout_nb_channels(b) == FF_LAYOUT2COUNT(a));
+    return !av_channel_layout_compare(a, b) ||
+           (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
+           (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
 }
 
 int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
@@ -869,7 +918,7 @@ int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fm
     }
     for (i = 0; i < fmts->nb_channel_layouts; i++) {
         for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
-            if (layouts_compatible(fmts->channel_layouts[i], fmts->channel_layouts[j])) {
+            if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) {
                 av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n");
                 return AVERROR(EINVAL);
             }
diff --git a/libavfilter/formats.h b/libavfilter/formats.h
index a884d15213..e55180f45c 100644
--- a/libavfilter/formats.h
+++ b/libavfilter/formats.h
@@ -83,7 +83,7 @@ struct AVFilterFormats {
  *   (e.g. AV_CH_LAYOUT_STEREO and FF_COUNT2LAYOUT(2).
  */
 struct AVFilterChannelLayouts {
-    uint64_t *channel_layouts;  ///< list of channel layouts
+    AVChannelLayout *channel_layouts; ///< list of channel layouts
     int    nb_channel_layouts;  ///< number of channel layouts
     char all_layouts;           ///< accept any known channel layout
     char all_counts;            ///< accept any channel layout or count
@@ -99,14 +99,16 @@ struct AVFilterChannelLayouts {
  * The result is only valid inside AVFilterChannelLayouts and immediately
  * related functions.
  */
-#define FF_COUNT2LAYOUT(c) (0x8000000000000000ULL | (c))
+#define FF_COUNT2LAYOUT(c) ((AVChannelLayout) { .order = AV_CHANNEL_ORDER_UNSPEC, .nb_channels = c })
 
 /**
  * Decode a channel count encoded as a channel layout.
  * Return 0 if the channel layout was a real one.
  */
-#define FF_LAYOUT2COUNT(l) (((l) & 0x8000000000000000ULL) ? \
-                           (int)((l) & 0x7FFFFFFF) : 0)
+#define FF_LAYOUT2COUNT(l) (((l)->order == AV_CHANNEL_ORDER_UNSPEC) ? \
+                            (l)->nb_channels : 0)
+
+#define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */
 
 /**
  * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct --
@@ -126,7 +128,7 @@ av_warn_unused_result
 AVFilterChannelLayouts *ff_all_channel_counts(void);
 
 av_warn_unused_result
-AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts);
+AVFilterChannelLayouts *ff_make_format64_list(const AVChannelLayout *fmts);
 
 /**
  * Helpers for query_formats() which set all free audio links to the same list
@@ -141,7 +143,7 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx,
  */
 av_warn_unused_result
 int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx,
-                                            const int64_t *fmts);
+                                            const AVChannelLayout *fmts);
 /**
  * Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
  */
@@ -178,7 +180,7 @@ av_warn_unused_result
 int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts);
 
 av_warn_unused_result
-int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout);
+int ff_add_channel_layout(AVFilterChannelLayouts **l, AVChannelLayout *channel_layout);
 
 /**
  * Add *ref as a new reference to f.
diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c
index cf8914b558..80f7bf6c98 100644
--- a/libavfilter/graphdump.c
+++ b/libavfilter/graphdump.c
@@ -30,6 +30,7 @@
 static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
 {
     const char *format;
+    char layout[128];
     AVBPrint dummy_buffer;
 
     if (!buf) {
@@ -49,7 +50,8 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
             format = av_x_if_null(av_get_sample_fmt_name(link->format), "?");
             av_bprintf(buf, "[%dHz %s:",
                        (int)link->sample_rate, format);
-            av_bprint_channel_layout(buf, link->channels, link->channel_layout);
+            av_channel_layout_describe(&link->ch_layout, layout, sizeof(layout));
+            av_bprintf(buf, "%s", layout);
             av_bprint_chars(buf, ']', 1);
             break;
 
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 1099b82b4b..3eecaca3fb 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -237,7 +237,7 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
  * @return >= 0 in case of success, a negative AVERROR code on error
  */
 av_warn_unused_result
-int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
+int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
                             void *log_ctx);
 
 void ff_update_link_current_pts(AVFilterLink *link, int64_t pts);
diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index b89a680883..3ebd279df7 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -189,23 +189,24 @@ static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
 {
     AVCodecParameters *dec_par = st->st->codecpar;
     char buf[256];
-    int64_t chl = av_get_default_channel_layout(dec_par->channels);
+    AVChannelLayout chl = { 0 };
 
-    if (!chl) {
+    av_channel_layout_default(&chl, dec_par->ch_layout.nb_channels);
+
+    if (!KNOWN(&chl)) {
         av_log(log_ctx, AV_LOG_ERROR,
                "Channel layout is not set in stream %d, and could not "
                "be guessed from the number of channels (%d)\n",
-               st_index, dec_par->channels);
+               st_index, dec_par->ch_layout.nb_channels);
         return AVERROR(EINVAL);
     }
 
-    av_get_channel_layout_string(buf, sizeof(buf), dec_par->channels, chl);
+    av_channel_layout_describe(&chl, buf, sizeof(buf));
     av_log(log_ctx, AV_LOG_WARNING,
            "Channel layout is not set in output stream %d, "
            "guessed channel layout is '%s'\n",
            st_index, buf);
-    dec_par->channel_layout = chl;
-    return 0;
+    return av_channel_layout_copy(&dec_par->ch_layout, &chl);
 }
 
 static av_cold int movie_common_init(AVFilterContext *ctx)
@@ -315,7 +316,7 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
         if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
             return ret;
         if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
-            !movie->st[i].st->codecpar->channel_layout) {
+            !KNOWN(&movie->st[i].st->codecpar->ch_layout)) {
             ret = guess_channel_layout(&movie->st[i], i, ctx);
             if (ret < 0)
                 return ret;
@@ -351,7 +352,7 @@ static int movie_query_formats(AVFilterContext *ctx)
 {
     MovieContext *movie = ctx->priv;
     int list[] = { 0, -1 };
-    int64_t list64[] = { 0, -1 };
+    AVChannelLayout list64[] = { { 0 }, { 0 } };
     int i, ret;
 
     for (i = 0; i < ctx->nb_outputs; i++) {
@@ -372,7 +373,7 @@ static int movie_query_formats(AVFilterContext *ctx)
             list[0] = c->sample_rate;
             if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->incfg.samplerates)) < 0)
                 return ret;
-            list64[0] = c->channel_layout;
+            list64[0] = c->ch_layout;
             if ((ret = ff_channel_layouts_ref(ff_make_format64_list(list64),
                                    &outlink->incfg.channel_layouts)) < 0)
                 return ret;
diff --git a/libavfilter/tests/filtfmts.c b/libavfilter/tests/filtfmts.c
index d793480344..909c1e8dc9 100644
--- a/libavfilter/tests/filtfmts.c
+++ b/libavfilter/tests/filtfmts.c
@@ -59,8 +59,7 @@ static void print_formats_internal(AVFilterLink **links, const AVFilterPad *pads
 
             for (unsigned j = 0; layouts && j < layouts->nb_channel_layouts; j++) {
                 char buf[256];
-                av_get_channel_layout_string(buf, sizeof(buf), -1,
-                                             layouts->channel_layouts[j]);
+                av_channel_layout_describe(&layouts->channel_layouts[j], buf, sizeof(buf));
                 printf("%s[%u] %s: chlayout:%s\n",
                        inout_string, i, pad_name, buf);
             }
diff --git a/libavfilter/tests/formats.c b/libavfilter/tests/formats.c
index c1e30e73ee..7b28ccf0b5 100644
--- a/libavfilter/tests/formats.c
+++ b/libavfilter/tests/formats.c
@@ -112,14 +112,18 @@ int main(void)
         "-1c",
         "60c",
         "65c",
+#if FF_API_OLD_CHANNEL_LAYOUT
         "2C",
         "60C",
         "65C",
+#endif
         "5.1",
         "stereo",
+#if FF_API_OLD_CHANNEL_LAYOUT
         "1+1+1+1",
         "1c+1c+1c+1c",
         "2c+1c",
+#endif
         "0x3",
     };
 
@@ -129,12 +133,12 @@ int main(void)
     }
 
     for ( i = 0; i<FF_ARRAY_ELEMS(teststrings); i++) {
-        int64_t layout = -1;
+        AVChannelLayout layout = { 0 };
         int count = -1;
         int ret;
         ret = ff_parse_channel_layout(&layout, &count, teststrings[i], NULL);
 
-        printf ("%d = ff_parse_channel_layout(%016"PRIX64", %2d, %s);\n", ret ? -1 : 0, layout, count, teststrings[i]);
+        printf ("%d = ff_parse_channel_layout(%016"PRIX64", %2d, %s);\n", ret ? -1 : 0, layout.order == AV_CHANNEL_ORDER_NATIVE ? layout.u.mask : 0, count, teststrings[i]);
     }
 
     return 0;
diff --git a/libavfilter/vaf_spectrumsynth.c b/libavfilter/vaf_spectrumsynth.c
index 674e9953b2..e0baf855a8 100644
--- a/libavfilter/vaf_spectrumsynth.c
+++ b/libavfilter/vaf_spectrumsynth.c
@@ -112,7 +112,7 @@ static int query_formats(AVFilterContext *ctx)
 
     formats = ff_make_format_list(sample_fmts);
     if ((ret = ff_formats_ref         (formats, &outlink->incfg.formats        )) < 0 ||
-        (ret = ff_add_channel_layout  (&layout, FF_COUNT2LAYOUT(s->channels))) < 0 ||
+        (ret = ff_add_channel_layout  (&layout, &FF_COUNT2LAYOUT(s->channels))) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0)
         return ret;
 
diff --git a/tests/ref/fate/filter-formats b/tests/ref/fate/filter-formats
index 17ff5b222f..fd692a2725 100644
--- a/tests/ref/fate/filter-formats
+++ b/tests/ref/fate/filter-formats
@@ -66,20 +66,20 @@ quad(side)
 7 channels (FL+FR+BC+SL+SR+DL+DR)
 8 channels (FL+FR+LFE+BC+SL+SR+DL+DR)
 8 channels (FL+FR+FC+BC+SL+SR+DL+DR)
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, blah);
-0 = ff_parse_channel_layout(0000000000000001,  1, 1);
-0 = ff_parse_channel_layout(0000000000000002,  1, 2);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, -1);
-0 = ff_parse_channel_layout(000000000000003C,  4, 60);
-0 = ff_parse_channel_layout(0000000000000041,  2, 65);
+-1 = ff_parse_channel_layout(0000000000000000, -1, blah);
+0 = ff_parse_channel_layout(0000000000000000,  1, 1);
+0 = ff_parse_channel_layout(0000000000000000,  2, 2);
+-1 = ff_parse_channel_layout(0000000000000000, -1, -1);
+0 = ff_parse_channel_layout(0000000000000000, 60, 60);
+0 = ff_parse_channel_layout(0000000000000000, 65, 65);
 0 = ff_parse_channel_layout(0000000000000004,  1, 1c);
 0 = ff_parse_channel_layout(0000000000000003,  2, 2c);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, -1c);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 60c);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 65c);
+-1 = ff_parse_channel_layout(0000000000000000, -1, -1c);
+0 = ff_parse_channel_layout(0000000000000000, 60, 60c);
+0 = ff_parse_channel_layout(0000000000000000, 65, 65c);
 0 = ff_parse_channel_layout(0000000000000000,  2, 2C);
 0 = ff_parse_channel_layout(0000000000000000, 60, 60C);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 65C);
+-1 = ff_parse_channel_layout(0000000000000000, -1, 65C);
 0 = ff_parse_channel_layout(000000000000003F,  6, 5.1);
 0 = ff_parse_channel_layout(0000000000000003,  2, stereo);
 0 = ff_parse_channel_layout(0000000000000001,  1, 1+1+1+1);
-- 
2.34.1



More information about the ffmpeg-devel mailing list