diff mbox series

[FFmpeg-devel,04/10] doc/examples/transcode: stop using avfilter_graph_alloc_filter() incorrectly

Message ID 20240925132921.11203-4-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/10] fftools/ffmpeg_filter: stop using avfilter_graph_alloc_filter() incorrectly | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Sept. 25, 2024, 1:29 p.m. UTC
See previous commits for details.
---
 doc/examples/transcode.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index cbe5088ef6..7d1e1826a3 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -283,10 +283,10 @@  static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
             goto end;
         }
 
-        ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
-                NULL, NULL, filter_graph);
-        if (ret < 0) {
+        buffersink_ctx = avfilter_graph_alloc_filter(filter_graph, buffersink, "out");
+        if (!buffersink_ctx) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
+            ret = AVERROR(ENOMEM);
             goto end;
         }
 
@@ -297,6 +297,12 @@  static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
             av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");
             goto end;
         }
+
+        ret = avfilter_init_dict(buffersink_ctx, NULL);
+        if (ret < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Cannot initialize buffer sink\n");
+            goto end;
+        }
     } else if (dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
         char buf[64];
         buffersrc = avfilter_get_by_name("abuffer");
@@ -322,10 +328,10 @@  static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
             goto end;
         }
 
-        ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
-                NULL, NULL, filter_graph);
-        if (ret < 0) {
+        buffersink_ctx = avfilter_graph_alloc_filter(filter_graph, buffersink, "out");
+        if (!buffersink_ctx) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer sink\n");
+            ret = AVERROR(ENOMEM);
             goto end;
         }
 
@@ -352,6 +358,12 @@  static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
             av_log(NULL, AV_LOG_ERROR, "Cannot set output sample rate\n");
             goto end;
         }
+
+        ret = avfilter_init_dict(buffersink_ctx, NULL);
+        if (ret < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Cannot initialize audio buffer sink\n");
+            goto end;
+        }
     } else {
         ret = AVERROR_UNKNOWN;
         goto end;