PR #23328 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23328
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23328.patch


>From 51e31f411edb9acf2ab1048904a05a0189d8df94 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 4 Jun 2026 11:23:02 +0200
Subject: [PATCH 1/3] doc/examples/transcode_aac: Don't access deprecated
 AVCodec.sample_fmts

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 doc/examples/transcode_aac.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c
index 20de08d93b..f3e48dd363 100644
--- a/doc/examples/transcode_aac.c
+++ b/doc/examples/transcode_aac.c
@@ -152,6 +152,7 @@ static int open_output_file(const char *filename,
     AVIOContext *output_io_context = NULL;
     AVStream *stream               = NULL;
     const AVCodec *output_codec    = NULL;
+    const void *sample_fmts;
     int error;
 
     /* Open the output file to write to it. */
@@ -207,8 +208,12 @@ static int open_output_file(const char *filename,
     /* Set the basic encoder parameters.
      * The input file's sample rate is used to avoid a sample rate conversion. 
*/
     av_channel_layout_default(&avctx->ch_layout, OUTPUT_CHANNELS);
+    error = avcodec_get_supported_config(avctx, NULL, 
AV_CODEC_CONFIG_SAMPLE_FORMAT,
+                                         0, &sample_fmts, NULL);
+    av_assert0(error >= 0);
+    avctx->sample_fmt     = sample_fmts ? *(const enum 
AVSampleFormat*)sample_fmts
+                                        : input_codec_context->sample_fmt;
     avctx->sample_rate    = input_codec_context->sample_rate;
-    avctx->sample_fmt     = output_codec->sample_fmts[0];
     avctx->bit_rate       = OUTPUT_BIT_RATE;
 
     /* Set the sample rate for the container. */
-- 
2.52.0


>From f80dd686f6c4a734fbc2cc657d6b7d470785b627 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 4 Jun 2026 12:03:00 +0200
Subject: [PATCH 2/3] doc/examples/mux: Don't access deprecated AVCodec fields

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 doc/examples/mux.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/doc/examples/mux.c b/doc/examples/mux.c
index 9b22c8dd1d..e037bc7815 100644
--- a/doc/examples/mux.c
+++ b/doc/examples/mux.c
@@ -127,7 +127,7 @@ static void add_stream(OutputStream *ost, AVFormatContext 
*oc,
                        enum AVCodecID codec_id)
 {
     AVCodecContext *c;
-    int i;
+    int ret;
 
     /* find the encoder */
     *codec = avcodec_find_encoder(codec_id);
@@ -157,21 +157,37 @@ static void add_stream(OutputStream *ost, AVFormatContext 
*oc,
     ost->enc = c;
 
     switch ((*codec)->type) {
-    case AVMEDIA_TYPE_AUDIO:
-        c->sample_fmt  = (*codec)->sample_fmts ?
-            (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
+    case AVMEDIA_TYPE_AUDIO: {
+        const void *codec_config;
         c->bit_rate    = 64000;
-        c->sample_rate = 44100;
-        if ((*codec)->supported_samplerates) {
-            c->sample_rate = (*codec)->supported_samplerates[0];
-            for (i = 0; (*codec)->supported_samplerates[i]; i++) {
-                if ((*codec)->supported_samplerates[i] == 44100)
+        ret = avcodec_get_supported_config(c, NULL, 
AV_CODEC_CONFIG_SAMPLE_FORMAT,
+                                           0, &codec_config, NULL);
+        if (ret < 0) {
+            fprintf(stderr, "Failed to get supported sample formats\n");
+            exit(1);
+        }
+        c->sample_fmt  = codec_config ? *(const enum 
AVSampleFormat*)codec_config
+                                      : AV_SAMPLE_FMT_FLTP;
+        ret = avcodec_get_supported_config(c, NULL, 
AV_CODEC_CONFIG_SAMPLE_RATE,
+                                           0, &codec_config, NULL);
+        if (ret < 0) {
+            fprintf(stderr, "Failed to get supported sample rates\n");
+            exit(1);
+        }
+        if (codec_config) {
+            const int *supported_samplerates = codec_config;
+            c->sample_rate = supported_samplerates[0];
+            for (; *supported_samplerates; supported_samplerates++) {
+                if (*supported_samplerates == 44100)
                     c->sample_rate = 44100;
             }
+        } else {
+            c->sample_rate = 44100;
         }
         av_channel_layout_copy(&c->ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
         ost->st->time_base = (AVRational){ 1, c->sample_rate };
         break;
+    }
 
     case AVMEDIA_TYPE_VIDEO:
         c->codec_id = codec_id;
-- 
2.52.0


>From bc36298f1ac365f136da0d4897716ff56e7c9bee Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 4 Jun 2026 12:14:07 +0200
Subject: [PATCH 3/3] doc/examples/encode_audio: Don't access deprecated
 AVCodec fields

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 doc/examples/encode_audio.c | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/doc/examples/encode_audio.c b/doc/examples/encode_audio.c
index 8be9e8a82a..a16c3a35c4 100644
--- a/doc/examples/encode_audio.c
+++ b/doc/examples/encode_audio.c
@@ -41,7 +41,17 @@
 /* check that a given sample format is supported by the encoder */
 static int check_sample_fmt(const AVCodec *codec, enum AVSampleFormat 
sample_fmt)
 {
-    const enum AVSampleFormat *p = codec->sample_fmts;
+    const void *out_config;
+    int ret = avcodec_get_supported_config(NULL, codec, 
AV_CODEC_CONFIG_SAMPLE_FORMAT,
+                                           0, &out_config, NULL);
+    if (ret < 0) {
+        fprintf(stderr, "Error getting supported sample formats\n");
+        exit(1);
+    }
+    const enum AVSampleFormat *p = out_config;
+
+    if (!p)
+        return 1;
 
     while (*p != AV_SAMPLE_FMT_NONE) {
         if (*p == sample_fmt)
@@ -54,13 +64,19 @@ static int check_sample_fmt(const AVCodec *codec, enum 
AVSampleFormat sample_fmt
 /* just pick the highest supported samplerate */
 static int select_sample_rate(const AVCodec *codec)
 {
-    const int *p;
+    const void *out_config;
+    int ret = avcodec_get_supported_config(NULL, codec, 
AV_CODEC_CONFIG_SAMPLE_RATE,
+                                           0, &out_config, NULL);
+    if (ret < 0) {
+        fprintf(stderr, "Error getting supported sample rates\n");
+        exit(1);
+    }
+    const int *p = out_config;
     int best_samplerate = 0;
 
-    if (!codec->supported_samplerates)
+    if (!p)
         return 44100;
 
-    p = codec->supported_samplerates;
     while (*p) {
         if (!best_samplerate || abs(44100 - *p) < abs(44100 - best_samplerate))
             best_samplerate = *p;
@@ -72,13 +88,19 @@ static int select_sample_rate(const AVCodec *codec)
 /* select layout with the highest channel count */
 static int select_channel_layout(const AVCodec *codec, AVChannelLayout *dst)
 {
-    const AVChannelLayout *p, *best_ch_layout;
+    const void *out_config;
+    int ret = avcodec_get_supported_config(NULL, codec, 
AV_CODEC_CONFIG_CHANNEL_LAYOUT,
+                                           0, &out_config, NULL);
+    if (ret < 0) {
+        fprintf(stderr, "Error getting supported channel layouts\n");
+        exit(1);
+    }
+    const AVChannelLayout *p = out_config, *best_ch_layout;
     int best_nb_channels   = 0;
 
-    if (!codec->ch_layouts)
+    if (!p)
         return av_channel_layout_copy(dst, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
 
-    p = codec->ch_layouts;
     while (p->nb_channels) {
         int nb_channels = p->nb_channels;
 
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to