[FFmpeg-devel] [PATCH 09/25] fftools/ffmpeg: add a function adding a destination filter for InputStream

Anton Khirnov anton at khirnov.net
Thu Apr 13 17:12:07 EEST 2023


This way filtering code does not directly mess with InputStream
internals. Will become more useful in following commits.
---
 fftools/ffmpeg.h        | 1 +
 fftools/ffmpeg_demux.c  | 6 ++++++
 fftools/ffmpeg_filter.c | 8 +++-----
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 17076f018d..d25377514e 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -880,6 +880,7 @@ void ifile_close(InputFile **f);
 int ifile_get_packet(InputFile *f, AVPacket **pkt);
 
 void ist_output_add(InputStream *ist, OutputStream *ost);
+void ist_filter_add(InputStream *ist, InputFilter *ifilter);
 
 /* iterate over all input streams in all input files;
  * pass NULL to start iteration */
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index b9849d1669..2d46dbf876 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -567,6 +567,12 @@ void ist_output_add(InputStream *ist, OutputStream *ost)
     ist->outputs[ist->nb_outputs - 1] = ost;
 }
 
+void ist_filter_add(InputStream *ist, InputFilter *ifilter)
+{
+    GROW_ARRAY(ist->filters, ist->nb_filters);
+    ist->filters[ist->nb_filters - 1] = ifilter;
+}
+
 static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
                                      enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 584f51ac3f..d2a185cf98 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -212,12 +212,11 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
     if (!ifilter->frame_queue)
         report_and_exit(AVERROR(ENOMEM));
 
-    GROW_ARRAY(ist->filters, ist->nb_filters);
-    ist->filters[ist->nb_filters - 1] = ifilter;
-
     GROW_ARRAY(filtergraphs, nb_filtergraphs);
     filtergraphs[nb_filtergraphs - 1] = fg;
 
+    ist_filter_add(ist, ifilter);
+
     return 0;
 }
 
@@ -319,8 +318,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
     if (!ifilter->frame_queue)
         report_and_exit(AVERROR(ENOMEM));
 
-    GROW_ARRAY(ist->filters, ist->nb_filters);
-    ist->filters[ist->nb_filters - 1] = ifilter;
+    ist_filter_add(ist, ifilter);
 }
 
 static int read_binary(const char *path, uint8_t **data, int *len)
-- 
2.39.1



More information about the ffmpeg-devel mailing list