[FFmpeg-devel] [PATCH 12/18] fftools/ffmpeg_filter: factor processing a single frame out of reap_filters()

Anton Khirnov anton at khirnov.net
Sat Aug 26 18:11:38 EEST 2023


This is easier to read.
---
 fftools/ffmpeg_filter.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 74b57191d1..5bf2431fb9 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1741,25 +1741,14 @@ int filtergraph_is_simple(const FilterGraph *fg)
     return fgp->is_simple;
 }
 
-int reap_filters(FilterGraph *fg, int flush)
+static int fg_output_step(OutputFilterPriv *ofp, int flush)
 {
-    FilterGraphPriv    *fgp = fgp_from_fg(fg);
+    FilterGraphPriv    *fgp = fgp_from_fg(ofp->ofilter.graph);
+    OutputStream       *ost = ofp->ofilter.ost;
     AVFrame *filtered_frame = fgp->frame;
-
-    if (!fg->graph)
-        return 0;
-
-    /* Reap all buffers present in the buffer sinks */
-    for (int i = 0; i < fg->nb_outputs; i++) {
-        OutputFilter   *ofilter = fg->outputs[i];
-        OutputStream       *ost = ofilter->ost;
-        OutputFilterPriv   *ofp = ofp_from_ofilter(ofilter);
         AVFilterContext *filter = ofp->filter;
-
-        int ret = 0;
-
-        while (1) {
             FrameData *fd;
+    int ret;
 
             ret = av_buffersink_get_frame_flags(filter, filtered_frame,
                                                AV_BUFFERSINK_FLAG_NO_REQUEST);
@@ -1774,11 +1763,11 @@ int reap_filters(FilterGraph *fg, int flush)
                         return ret;
                 }
 
-                break;
+                return 1;
             }
             if (ost->finished) {
                 av_frame_unref(filtered_frame);
-                continue;
+                return 0;
             }
 
             if (filtered_frame->pts != AV_NOPTS_VALUE) {
@@ -1823,6 +1812,24 @@ int reap_filters(FilterGraph *fg, int flush)
                 return ret;
 
             ofp->got_frame = 1;
+
+    return 0;
+}
+
+int reap_filters(FilterGraph *fg, int flush)
+{
+    if (!fg->graph)
+        return 0;
+
+    /* Reap all buffers present in the buffer sinks */
+    for (int i = 0; i < fg->nb_outputs; i++) {
+        OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[i]);
+        int ret = 0;
+
+        while (!ret) {
+            ret = fg_output_step(ofp, flush);
+            if (ret < 0)
+                return ret;
         }
     }
 
-- 
2.40.1



More information about the ffmpeg-devel mailing list