[FFmpeg-cvslog] fftools/ffmpeg: use an int for nb_threads

James Almer git at videolan.org
Mon Feb 17 14:46:28 EET 2025


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Fri Feb 14 13:17:43 2025 -0300| [0e7c2a6287f977c30e08e2a211385c6a80614fe8] | committer: James Almer

fftools/ffmpeg: use an int for nb_threads

Removes unnecessary allocations.

Signed-off-by: James Almer <jamrial at gmail.com>

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

 fftools/ffmpeg.h          |  2 +-
 fftools/ffmpeg_filter.c   | 16 ++++++----------
 fftools/ffmpeg_mux_init.c |  4 ++--
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9439be0f41..6cc0da05a0 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -316,7 +316,7 @@ typedef struct OutputFilterOptions {
     AVDictionary       *sws_opts;
     AVDictionary       *swr_opts;
 
-    const char         *nb_threads;
+    int64_t             nb_threads;
 
     // A combination of OFilterFlags.
     unsigned            flags;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index a0d04fd76f..800e2a3f06 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -60,7 +60,7 @@ typedef struct FilterGraphPriv {
 
     const char      *graph_desc;
 
-    char            *nb_threads;
+    int              nb_threads;
 
     // frame for temporarily holding output from the filtergraph
     AVFrame         *frame;
@@ -1042,7 +1042,6 @@ void fg_free(FilterGraph **pfg)
     }
     av_freep(&fg->outputs);
     av_freep(&fgp->graph_desc);
-    av_freep(&fgp->nb_threads);
 
     av_frame_free(&fgp->frame);
     av_frame_free(&fgp->frame_enc);
@@ -1097,6 +1096,7 @@ int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch)
     fg->class       = &fg_class;
     fgp->graph_desc = graph_desc;
     fgp->disable_conversions = !auto_conversion_filters;
+    fgp->nb_threads          = -1;
     fgp->sch                 = sch;
 
     snprintf(fgp->log_name, sizeof(fgp->log_name), "fc#%d", fg->index);
@@ -1247,12 +1247,8 @@ int fg_create_simple(FilterGraph **pfg,
     if (ret < 0)
         return ret;
 
-    if (opts->nb_threads) {
-        av_freep(&fgp->nb_threads);
-        fgp->nb_threads = av_strdup(opts->nb_threads);
-        if (!fgp->nb_threads)
-            return AVERROR(ENOMEM);
-    }
+    if (opts->nb_threads >= 0)
+        fgp->nb_threads = opts->nb_threads;
 
     return 0;
 }
@@ -1936,8 +1932,8 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt)
             ret = av_opt_set(fgt->graph, "threads", filter_nbthreads, 0);
             if (ret < 0)
                 goto fail;
-        } else if (fgp->nb_threads) {
-            ret = av_opt_set(fgt->graph, "threads", fgp->nb_threads, 0);
+        } else if (fgp->nb_threads >= 0) {
+            ret = av_opt_set_int(fgt->graph, "threads", fgp->nb_threads, 0);
             if (ret < 0)
                 return ret;
         }
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 944176ca5d..4a973e5286 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -930,6 +930,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter,
         .ts_offset        = mux->of.start_time == AV_NOPTS_VALUE ?
                             0 : mux->of.start_time,
         .vs               = vs,
+        .nb_threads       = -1,
 
         .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt |
                  OFILTER_FLAG_AUTOSCALE       * !!autoscale    |
@@ -982,7 +983,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter,
     }
 
     if (threads_manual) {
-        ret = av_opt_get(enc_ctx, "threads", 0, (uint8_t**)&opts.nb_threads);
+        ret = av_opt_get_int(enc_ctx, "threads", 0, &opts.nb_threads);
         if (ret < 0)
             return ret;
     }
@@ -1002,7 +1003,6 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter,
             ost->filter = ost->fg_simple->outputs[0];
 
     }
-    av_freep(&opts.nb_threads);
     if (ret < 0)
         return ret;
 



More information about the ffmpeg-cvslog mailing list