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

Marton Balint cus at passwd.hu
Sat Apr 25 21:55:55 EEST 2020


Signed-off-by: Marton Balint <cus at 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);
         }
     }
-- 
2.16.4



More information about the ffmpeg-devel mailing list