diff mbox series

[FFmpeg-devel,2/2] ffmpeg: allow to pass "auto" to filter_threads

Message ID 20210903133638.812-2-jamrial@gmail.com
State Accepted
Commit 7453d3482a02452d67ca2fa2a2ed1e6094fdddeb
Headers show
Series [FFmpeg-devel,1/2] avfilter/avfiltergraph: add an "auto" constant to the threads option | expand

Checks

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

Commit Message

James Almer Sept. 3, 2021, 1:36 p.m. UTC
This way it accepts the same values as the libavcodec specific option "threads"

Fixes FATE with THREADS=auto which was broken in bdc1bdf3f5.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 fftools/ffmpeg.c        |  1 +
 fftools/ffmpeg.h        |  2 +-
 fftools/ffmpeg_filter.c |  7 +++++--
 fftools/ffmpeg_opt.c    | 11 +++++++++--
 4 files changed, 16 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index b0ce7c7c32..eb5a32572a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -653,6 +653,7 @@  static void ffmpeg_cleanup(int ret)
                    av_err2str(AVERROR(errno)));
     }
     av_freep(&vstats_filename);
+    av_freep(&filter_nbthreads);
 
     av_freep(&input_streams);
     av_freep(&input_files);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index d2dd7ca092..d583a1e8d0 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -633,7 +633,7 @@  extern AVIOContext *progress_avio;
 extern float max_error_rate;
 extern char *videotoolbox_pixfmt;
 
-extern int filter_nbthreads;
+extern char *filter_nbthreads;
 extern int filter_complex_nbthreads;
 extern int vstats_version;
 extern int auto_conversion_filters;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 21d54cc8ae..dc6664260d 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -968,8 +968,11 @@  int configure_filtergraph(FilterGraph *fg)
         char args[512];
         AVDictionaryEntry *e = NULL;
 
-        fg->graph->nb_threads = filter_nbthreads;
-        if (!fg->graph->nb_threads) {
+        if (filter_nbthreads) {
+            ret = av_opt_set(fg->graph, "threads", filter_nbthreads, 0);
+            if (ret < 0)
+                goto fail;
+        } else {
             e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
             if (e)
                 av_opt_set(fg->graph, "threads", e->value, 0);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 428934a3d8..a01939c733 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -169,7 +169,7 @@  int qp_hist           = 0;
 int stdin_interaction = 1;
 int frame_bits_per_raw_sample = 0;
 float max_error_rate  = 2.0/3;
-int filter_nbthreads = 0;
+char *filter_nbthreads;
 int filter_complex_nbthreads = 0;
 int vstats_version = 2;
 int auto_conversion_filters = 1;
@@ -264,6 +264,13 @@  static AVDictionary *strip_specifiers(AVDictionary *dict)
     return ret;
 }
 
+static int opt_filter_threads(void *optctx, const char *opt, const char *arg)
+{
+    av_free(filter_nbthreads);
+    filter_nbthreads = av_strdup(arg);
+    return 0;
+}
+
 static int opt_abort_on(void *optctx, const char *opt, const char *arg)
 {
     static const AVOption opts[] = {
@@ -3620,7 +3627,7 @@  const OptionDef options[] = {
         "set profile", "profile" },
     { "filter",         HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filters) },
         "set stream filtergraph", "filter_graph" },
-    { "filter_threads",  HAS_ARG | OPT_INT,                          { &filter_nbthreads },
+    { "filter_threads", HAS_ARG,                                     { .func_arg = opt_filter_threads },
         "number of non-complex filter threads" },
     { "filter_script",  HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filter_scripts) },
         "read stream filtergraph description from a file", "filename" },