[FFmpeg-cvslog] fftools/ffmpeg_filter: accept a name from its upstream input

Anton Khirnov git at videolan.org
Wed Feb 21 11:45:09 EET 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Feb 13 12:18:27 2024 +0100| [bd3c1c194bd2252ada4cfd025b14ae091a30b3b5] | committer: Anton Khirnov

fftools/ffmpeg_filter: accept a name from its upstream input

Do not construct the name manually from input file/stream indices.

This is a step towards avoiding the assumption that filtergraph inputs
are always fed by demuxers.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bd3c1c194bd2252ada4cfd025b14ae091a30b3b5
---

 fftools/ffmpeg.h        |  2 ++
 fftools/ffmpeg_demux.c  |  4 ++++
 fftools/ffmpeg_filter.c | 21 ++++++++-------------
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ca9ffb08af..b6302245c0 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -253,6 +253,8 @@ typedef struct OptionsContext {
 typedef struct InputFilterOptions {
     int64_t             trim_start_us;
     int64_t             trim_end_us;
+
+    uint8_t            *name;
 } InputFilterOptions;
 
 typedef struct InputFilter {
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index abda4ad0d9..4cbad80e17 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1009,6 +1009,10 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
                           AV_NOPTS_VALUE : tsoffset;
     opts->trim_end_us   = d->recording_time;
 
+    opts->name = av_strdup(ds->dec_name);
+    if (!opts->name)
+        return AVERROR(ENOMEM);
+
     return ds->sch_idx_dec;
 }
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index c411b882de..0f57035104 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -889,6 +889,7 @@ void fg_free(FilterGraph **pfg)
 
         av_buffer_unref(&ifp->hw_frames_ctx);
         av_freep(&ifp->linklabel);
+        av_freep(&ifp->opts.name);
         av_freep(&ifilter->name);
         av_freep(&fg->inputs[j]);
     }
@@ -1475,7 +1476,6 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
     const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
     const AVPixFmtDescriptor *desc;
     InputStream *ist = ifp->ist;
-    InputFile     *f = ist->file;
     AVRational fr = ist->framerate;
     AVRational sar;
     AVBPrint args;
@@ -1506,8 +1506,8 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
              ifp->color_space, ifp->color_range);
     if (fr.num && fr.den)
         av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
-    snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
-             f->index, ist->index);
+    snprintf(name, sizeof(name), "graph %d input from stream %s", fg->index,
+             ifp->opts.name);
 
 
     if ((ret = avfilter_graph_create_filter(&ifp->filter, buffer_filt, name,
@@ -1558,8 +1558,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
             return ret;
     }
 
-    snprintf(name, sizeof(name), "trim_in_%d_%d",
-             f->index, ist->index);
+    snprintf(name, sizeof(name), "trim_in_%s", ifp->opts.name);
     ret = insert_trim(ifp->opts.trim_start_us, ifp->opts.trim_end_us,
                       &last_filter, &pad_idx, name);
     if (ret < 0)
@@ -1580,8 +1579,6 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
     InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
     AVFilterContext *last_filter;
     const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
-    InputStream *ist = ifp->ist;
-    InputFile     *f = ist->file;
     AVBPrint args;
     char name[255];
     int ret, pad_idx = 0;
@@ -1599,8 +1596,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
         av_channel_layout_describe_bprint(&ifp->ch_layout, &args);
     } else
         av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels);
-    snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index,
-             f->index, ist->index);
+    snprintf(name, sizeof(name), "graph_%d_in_%s", fg->index, ifp->opts.name);
 
     if ((ret = avfilter_graph_create_filter(&ifp->filter, abuffer_filt,
                                             name, args.str, NULL,
@@ -1608,8 +1604,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
         return ret;
     last_filter = ifp->filter;
 
-    snprintf(name, sizeof(name), "trim for input stream %d:%d",
-             f->index, ist->index);
+    snprintf(name, sizeof(name), "trim for input stream %s", ifp->opts.name);
     ret = insert_trim(ifp->opts.trim_start_us, ifp->opts.trim_end_us,
                       &last_filter, &pad_idx, name);
     if (ret < 0)
@@ -2566,8 +2561,8 @@ static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter,
 
         if (ifp->format < 0) {
             av_log(NULL, AV_LOG_ERROR,
-                   "Cannot determine format of input stream %d:%d after EOF\n",
-                   ifp->ist->file->index, ifp->ist->index);
+                   "Cannot determine format of input %s after EOF\n",
+                   ifp->opts.name);
             return AVERROR_INVALIDDATA;
         }
     }



More information about the ffmpeg-cvslog mailing list