aboutsummaryrefslogtreecommitdiffstats
path: root/fftools
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-06-08 13:28:33 +0200
committerAnton Khirnov <anton@khirnov.net>2023-07-20 20:30:13 +0200
commit3a89e6d35261a261bae10fa856ea512385df6076 (patch)
tree42aa993b7d6ade3bc049e3c22cf0ff084b3000da /fftools
parent9d44eb8af5392ee208ca22e5997c27ab3aa2afc2 (diff)
downloadffmpeg-3a89e6d35261a261bae10fa856ea512385df6076.tar.gz
fftools/ffmpeg_filter: restrict reap_filters() to a single filtergraph
This is more natural, as all except one of its callers require processing only one filtergraph.
Diffstat (limited to 'fftools')
-rw-r--r--fftools/ffmpeg.c10
-rw-r--r--fftools/ffmpeg.h4
-rw-r--r--fftools/ffmpeg_filter.c33
3 files changed, 27 insertions, 20 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index cbeddab125..27c4e7ef26 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1171,7 +1171,15 @@ static int transcode_step(OutputStream *ost)
if (ret < 0)
return ret == AVERROR_EOF ? 0 : ret;
- return reap_filters(0);
+ // process_input() above might have caused output to become available
+ // in multiple filtergraphs, so we process all of them
+ for (int i = 0; i < nb_filtergraphs; i++) {
+ ret = reap_filters(filtergraphs[i], 0);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
}
/*
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index f45ddf33b2..1b799832ad 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -765,12 +765,12 @@ void fg_free(FilterGraph **pfg);
int fg_transcode_step(FilterGraph *graph, InputStream **best_ist);
/**
- * Get and encode new output from any of the filtergraphs, without causing
+ * Get and encode new output from specified filtergraph, without causing
* activity.
*
* @return 0 for success, <0 for severe errors
*/
-int reap_filters(int flush);
+int reap_filters(FilterGraph *fg, int flush);
int ffmpeg_parse_options(int argc, char **argv);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index e14b8f0f3c..49e0800e6e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1695,23 +1695,22 @@ int filtergraph_is_simple(const FilterGraph *fg)
return fgp->is_simple;
}
-int reap_filters(int flush)
+int reap_filters(FilterGraph *fg, int flush)
{
- /* Reap all buffers present in the buffer sinks */
- for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
- OutputFilterPriv *ofp;
- FilterGraphPriv *fgp;
- AVFrame *filtered_frame;
- AVFilterContext *filter;
- int ret = 0;
+ FilterGraphPriv *fgp = fgp_from_fg(fg);
+ AVFrame *filtered_frame = fgp->frame;
- if (!ost->filter || !ost->filter->graph->graph)
- continue;
- fgp = fgp_from_fg(ost->filter->graph);
- ofp = ofp_from_ofilter(ost->filter);
- filter = ofp->filter;
+ 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;
- filtered_frame = fgp->frame;
+ int ret = 0;
while (1) {
FrameData *fd;
@@ -1931,7 +1930,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
return ret;
}
- ret = reap_filters(0);
+ ret = reap_filters(fg, 0);
if (ret < 0 && ret != AVERROR_EOF) {
av_log(fg, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
return ret;
@@ -2000,10 +1999,10 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
*best_ist = NULL;
ret = avfilter_graph_request_oldest(graph->graph);
if (ret >= 0)
- return reap_filters(0);
+ return reap_filters(graph, 0);
if (ret == AVERROR_EOF) {
- reap_filters(1);
+ reap_filters(graph, 1);
for (int i = 0; i < graph->nb_outputs; i++) {
OutputFilter *ofilter = graph->outputs[i];
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);