diff mbox series

[FFmpeg-devel,3/3] fftools/ffmpeg_opt: use av_bsf_list_parse_str for parsing bsf lists

Message ID 20200425185555.19111-3-cus@passwd.hu
State New
Headers show
Series [FFmpeg-devel,1/3] fftools/ffmpeg: use a bsf list instead of individual bsfs | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Marton Balint April 25, 2020, 6:55 p.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 fftools/ffmpeg_opt.c | 57 +++-------------------------------------------------
 1 file changed, 3 insertions(+), 54 deletions(-)

Comments

James Almer April 26, 2020, 10:10 p.m. UTC | #1
On 4/25/2020 3:55 PM, Marton Balint wrote:
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  fftools/ffmpeg_opt.c | 57 +++-------------------------------------------------
>  1 file changed, 3 insertions(+), 54 deletions(-)
> 
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index b52aa28626..dc42fb19d6 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -1416,7 +1416,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
>  {
>      OutputStream *ost;
>      AVStream *st = avformat_new_stream(oc, NULL);
> -    AVBSFList *bsf_list = NULL;
>      int idx      = oc->nb_streams - 1, ret = 0;
>      const char *bsfs = NULL, *time_base = NULL;
>      char *next, *codec_tag = NULL;
> @@ -1536,60 +1535,10 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
>      MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
>  
>      MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
> -    while (bsfs && *bsfs) {
> -        const AVBitStreamFilter *filter;
> -        char *bsf, *bsf_options_str, *bsf_name;
> -        AVBSFContext *bsf_ctx;
> -
> -        bsf = av_get_token(&bsfs, ",");
> -        if (!bsf)
> -            exit_program(1);
> -        bsf_name = av_strtok(bsf, "=", &bsf_options_str);
> -        if (!bsf_name)
> -            exit_program(1);
> -
> -        filter = av_bsf_get_by_name(bsf_name);
> -        if (!filter) {
> -            av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
> -            exit_program(1);
> -        }
> -
> -        ret = av_bsf_alloc(filter, &bsf_ctx);
> -        if (ret < 0) {
> -            av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream filter context\n");
> -            exit_program(1);
> -        }
> -
> -        if (bsf_options_str && filter->priv_class) {
> -            const AVOption *opt = av_opt_next(bsf_ctx->priv_data, NULL);
> -            const char * shorthand[2] = {NULL};
> -
> -            if (opt)
> -                shorthand[0] = opt->name;
> -
> -            ret = av_opt_set_from_string(bsf_ctx->priv_data, bsf_options_str, shorthand, "=", ":");
> -            if (ret < 0) {
> -                av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
> -                exit_program(1);
> -            }
> -        }
> -
> -        if (!bsf_list)
> -            bsf_list = av_bsf_list_alloc();
> -        if (!bsf_list || av_bsf_list_append(bsf_list, bsf_ctx) < 0) {
> -            av_log(NULL, AV_LOG_ERROR, "Failed to allocate or append to bsf list\n");
> -            exit_program(1);
> -        }
> -
> -        av_freep(&bsf);
> -
> -        if (*bsfs)
> -            bsfs++;
> -    }
> -    if (bsf_list) {
> -        ret = av_bsf_list_finalize(&bsf_list, &ost->bsf_ctx);
> +    if (bsfs && *bsfs) {
> +        ret = av_bsf_list_parse_str(bsfs, &ost->bsf_ctx);
>          if (ret < 0) {
> -            av_log(NULL, AV_LOG_ERROR, "Failed to finalize bsf list\n");
> +            av_log(NULL, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
>              exit_program(1);
>          }
>      }

Maybe this patch could instead be merged with 1/3 and applied after 2/3?
Marton Balint May 1, 2020, 3:43 p.m. UTC | #2
On Sun, 26 Apr 2020, James Almer wrote:

> On 4/25/2020 3:55 PM, Marton Balint wrote:
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>>  fftools/ffmpeg_opt.c | 57 +++-------------------------------------------------
>>  1 file changed, 3 insertions(+), 54 deletions(-)
>> 
>> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
>> index b52aa28626..dc42fb19d6 100644
>> --- a/fftools/ffmpeg_opt.c
>> +++ b/fftools/ffmpeg_opt.c
>> @@ -1416,7 +1416,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
>>  {
>>      OutputStream *ost;
>>      AVStream *st = avformat_new_stream(oc, NULL);
>> -    AVBSFList *bsf_list = NULL;
>>      int idx      = oc->nb_streams - 1, ret = 0;
>>      const char *bsfs = NULL, *time_base = NULL;
>>      char *next, *codec_tag = NULL;
>> @@ -1536,60 +1535,10 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
>>      MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
>>
>>      MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
>> -    while (bsfs && *bsfs) {
>> -        const AVBitStreamFilter *filter;
>> -        char *bsf, *bsf_options_str, *bsf_name;
>> -        AVBSFContext *bsf_ctx;
>> -
>> -        bsf = av_get_token(&bsfs, ",");
>> -        if (!bsf)
>> -            exit_program(1);
>> -        bsf_name = av_strtok(bsf, "=", &bsf_options_str);
>> -        if (!bsf_name)
>> -            exit_program(1);
>> -
>> -        filter = av_bsf_get_by_name(bsf_name);
>> -        if (!filter) {
>> -            av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
>> -            exit_program(1);
>> -        }
>> -
>> -        ret = av_bsf_alloc(filter, &bsf_ctx);
>> -        if (ret < 0) {
>> -            av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream filter context\n");
>> -            exit_program(1);
>> -        }
>> -
>> -        if (bsf_options_str && filter->priv_class) {
>> -            const AVOption *opt = av_opt_next(bsf_ctx->priv_data, NULL);
>> -            const char * shorthand[2] = {NULL};
>> -
>> -            if (opt)
>> -                shorthand[0] = opt->name;
>> -
>> -            ret = av_opt_set_from_string(bsf_ctx->priv_data, bsf_options_str, shorthand, "=", ":");
>> -            if (ret < 0) {
>> -                av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
>> -                exit_program(1);
>> -            }
>> -        }
>> -
>> -        if (!bsf_list)
>> -            bsf_list = av_bsf_list_alloc();
>> -        if (!bsf_list || av_bsf_list_append(bsf_list, bsf_ctx) < 0) {
>> -            av_log(NULL, AV_LOG_ERROR, "Failed to allocate or append to bsf list\n");
>> -            exit_program(1);
>> -        }
>> -
>> -        av_freep(&bsf);
>> -
>> -        if (*bsfs)
>> -            bsfs++;
>> -    }
>> -    if (bsf_list) {
>> -        ret = av_bsf_list_finalize(&bsf_list, &ost->bsf_ctx);
>> +    if (bsfs && *bsfs) {
>> +        ret = av_bsf_list_parse_str(bsfs, &ost->bsf_ctx);
>>          if (ret < 0) {
>> -            av_log(NULL, AV_LOG_ERROR, "Failed to finalize bsf list\n");
>> +            av_log(NULL, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
>>              exit_program(1);
>>          }
>>      }
>
> Maybe this patch could instead be merged with 1/3 and applied after 2/3?

Will do and will apply soon.

Regards,
Marton
Marton Balint May 2, 2020, 5:41 p.m. UTC | #3
On Fri, 1 May 2020, Marton Balint wrote:

>
>
> On Sun, 26 Apr 2020, James Almer wrote:
>
>> On 4/25/2020 3:55 PM, Marton Balint wrote:
>>> Signed-off-by: Marton Balint <cus@passwd.hu>
>>> ---
>>>  fftools/ffmpeg_opt.c | 57 
> +++-------------------------------------------------
>>>  1 file changed, 3 insertions(+), 54 deletions(-)
>>> 
>>> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
>>> index b52aa28626..dc42fb19d6 100644
>>> --- a/fftools/ffmpeg_opt.c
>>> +++ b/fftools/ffmpeg_opt.c
>>> @@ -1416,7 +1416,6 @@ static OutputStream 
> *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
>>>  {
>>>      OutputStream *ost;
>>>      AVStream *st = avformat_new_stream(oc, NULL);
>>> -    AVBSFList *bsf_list = NULL;
>>>      int idx      = oc->nb_streams - 1, ret = 0;
>>>      const char *bsfs = NULL, *time_base = NULL;
>>>      char *next, *codec_tag = NULL;
>>> @@ -1536,60 +1535,10 @@ static OutputStream 
> *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
>>>      MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc 
> ,st);
>>>
>>>      MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
>>> -    while (bsfs && *bsfs) {
>>> -        const AVBitStreamFilter *filter;
>>> -        char *bsf, *bsf_options_str, *bsf_name;
>>> -        AVBSFContext *bsf_ctx;
>>> -
>>> -        bsf = av_get_token(&bsfs, ",");
>>> -        if (!bsf)
>>> -            exit_program(1);
>>> -        bsf_name = av_strtok(bsf, "=", &bsf_options_str);
>>> -        if (!bsf_name)
>>> -            exit_program(1);
>>> -
>>> -        filter = av_bsf_get_by_name(bsf_name);
>>> -        if (!filter) {
>>> -            av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", 
> bsf_name);
>>> -            exit_program(1);
>>> -        }
>>> -
>>> -        ret = av_bsf_alloc(filter, &bsf_ctx);
>>> -        if (ret < 0) {
>>> -            av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream 
> filter context\n");
>>> -            exit_program(1);
>>> -        }
>>> -
>>> -        if (bsf_options_str && filter->priv_class) {
>>> -            const AVOption *opt = av_opt_next(bsf_ctx->priv_data, NULL);
>>> -            const char * shorthand[2] = {NULL};
>>> -
>>> -            if (opt)
>>> -                shorthand[0] = opt->name;
>>> -
>>> -            ret = av_opt_set_from_string(bsf_ctx->priv_data, 
> bsf_options_str, shorthand, "=", ":");
>>> -            if (ret < 0) {
>>> -                av_log(NULL, AV_LOG_ERROR, "Error parsing options for 
> bitstream filter %s\n", bsf_name);
>>> -                exit_program(1);
>>> -            }
>>> -        }
>>> -
>>> -        if (!bsf_list)
>>> -            bsf_list = av_bsf_list_alloc();
>>> -        if (!bsf_list || av_bsf_list_append(bsf_list, bsf_ctx) < 0) {
>>> -            av_log(NULL, AV_LOG_ERROR, "Failed to allocate or append to 
> bsf list\n");
>>> -            exit_program(1);
>>> -        }
>>> -
>>> -        av_freep(&bsf);
>>> -
>>> -        if (*bsfs)
>>> -            bsfs++;
>>> -    }
>>> -    if (bsf_list) {
>>> -        ret = av_bsf_list_finalize(&bsf_list, &ost->bsf_ctx);
>>> +    if (bsfs && *bsfs) {
>>> +        ret = av_bsf_list_parse_str(bsfs, &ost->bsf_ctx);
>>>          if (ret < 0) {
>>> -            av_log(NULL, AV_LOG_ERROR, "Failed to finalize bsf list\n");
>>> +            av_log(NULL, AV_LOG_ERROR, "Error parsing bitstream filter 
> sequence '%s': %s\n", bsfs, av_err2str(ret));
>>>              exit_program(1);
>>>          }
>>>      }
>>
>> Maybe this patch could instead be merged with 1/3 and applied after 2/3?
>
> Will do and will apply soon.

Applied.

Regards,
Marton
diff mbox series

Patch

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index b52aa28626..dc42fb19d6 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1416,7 +1416,6 @@  static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
 {
     OutputStream *ost;
     AVStream *st = avformat_new_stream(oc, NULL);
-    AVBSFList *bsf_list = NULL;
     int idx      = oc->nb_streams - 1, ret = 0;
     const char *bsfs = NULL, *time_base = NULL;
     char *next, *codec_tag = NULL;
@@ -1536,60 +1535,10 @@  static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
     MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
 
     MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
-    while (bsfs && *bsfs) {
-        const AVBitStreamFilter *filter;
-        char *bsf, *bsf_options_str, *bsf_name;
-        AVBSFContext *bsf_ctx;
-
-        bsf = av_get_token(&bsfs, ",");
-        if (!bsf)
-            exit_program(1);
-        bsf_name = av_strtok(bsf, "=", &bsf_options_str);
-        if (!bsf_name)
-            exit_program(1);
-
-        filter = av_bsf_get_by_name(bsf_name);
-        if (!filter) {
-            av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
-            exit_program(1);
-        }
-
-        ret = av_bsf_alloc(filter, &bsf_ctx);
-        if (ret < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream filter context\n");
-            exit_program(1);
-        }
-
-        if (bsf_options_str && filter->priv_class) {
-            const AVOption *opt = av_opt_next(bsf_ctx->priv_data, NULL);
-            const char * shorthand[2] = {NULL};
-
-            if (opt)
-                shorthand[0] = opt->name;
-
-            ret = av_opt_set_from_string(bsf_ctx->priv_data, bsf_options_str, shorthand, "=", ":");
-            if (ret < 0) {
-                av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
-                exit_program(1);
-            }
-        }
-
-        if (!bsf_list)
-            bsf_list = av_bsf_list_alloc();
-        if (!bsf_list || av_bsf_list_append(bsf_list, bsf_ctx) < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Failed to allocate or append to bsf list\n");
-            exit_program(1);
-        }
-
-        av_freep(&bsf);
-
-        if (*bsfs)
-            bsfs++;
-    }
-    if (bsf_list) {
-        ret = av_bsf_list_finalize(&bsf_list, &ost->bsf_ctx);
+    if (bsfs && *bsfs) {
+        ret = av_bsf_list_parse_str(bsfs, &ost->bsf_ctx);
         if (ret < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Failed to finalize bsf list\n");
+            av_log(NULL, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
             exit_program(1);
         }
     }