[FFmpeg-devel] [PATCH] fftools/cmdutils: Allow expressions for opt_cpucount()

Michael Niedermayer michael at niedermayer.cc
Sat Jul 17 19:21:59 EEST 2021


This allows for example
"-cpucount cpu/2" to use half the available CPUs

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 fftools/cmdutils.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 6e875104fd..a902354669 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -859,11 +859,12 @@ int opt_cpucount(void *optctx, const char *opt, const char *arg)
     int ret;
     int count;
 
-    static const AVOption opts[] = {
-        {"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, INT_MAX, NULL},
+    AVOption opts[] = {
+        {"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, INT_MAX, 0, "val"},
+        {"cpu", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1}, 0, 0, 0, "val"},
         {NULL},
     };
-    static const AVClass class = {
+    const AVClass class = {
         .class_name = "cpucount",
         .item_name  = av_default_item_name,
         .option     = opts,
@@ -871,6 +872,8 @@ int opt_cpucount(void *optctx, const char *opt, const char *arg)
     };
     const AVClass *pclass = &class;
 
+    opts[1].default_val.i64 = av_cpu_count();
+
     ret = av_opt_eval_int(&pclass, opts, arg, &count);
 
     if (!ret) {
-- 
2.17.1



More information about the ffmpeg-devel mailing list