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

James Almer jamrial at gmail.com
Sat Jul 17 22:25:42 EEST 2021


On 7/17/2021 2:22 PM, James Almer wrote:
> On 7/17/2021 1:21 PM, Michael Niedermayer wrote:
>> 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();
> 
> You could set this directly as the default value instead of -1 above.
> 
> Should be ok either way.

Actually, the "cpu" constant should be documented.

> 
>> +
>>       ret = av_opt_eval_int(&pclass, opts, arg, &count);
>>       if (!ret) {
>>
> 



More information about the ffmpeg-devel mailing list