[FFmpeg-cvslog] lavf: add "disposition" AVOption to AVStream AVClass

Anton Khirnov git at videolan.org
Tue Nov 16 12:06:09 EET 2021


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Nov 12 15:15:07 2021 +0100| [a4c5d241ec215cfa680c5fa706377e40d18e8040] | committer: Anton Khirnov

lavf: add "disposition" AVOption to AVStream AVClass

Use it to remove custom disposition parsing code from ffmpeg.c

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

 doc/APIchanges      |  1 +
 fftools/ffmpeg.c    | 40 ++++++++++++----------------------------
 libavformat/utils.c | 24 ++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 53f229d41a..ad57ae29d6 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -18,6 +18,7 @@ API changes, most recent first:
   Add av_stream_get_class(). Schedule adding AVStream.av_class at libavformat
   major version 60.
   Add av_disposition_to_string() and av_disposition_from_string().
+  Add "disposition" AVOption to AVStream's class.
 
 2021-11-12 - xxxxxxxxxx - lavu 57.8.100 - hwcontext_vulkan.h
   Added AVFrame.sem_value, AVVulkanDeviceContext.queue_family_encode_index,
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d141f34df9..65d6a2668d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3665,34 +3665,18 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame,
 
     // parse user provided disposition, and update stream values
     if (ost->disposition) {
-        static const AVOption opts[] = {
-            { "disposition"         , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
-            { "default"             , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT           },    .unit = "flags" },
-            { "dub"                 , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB               },    .unit = "flags" },
-            { "original"            , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL          },    .unit = "flags" },
-            { "comment"             , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT           },    .unit = "flags" },
-            { "lyrics"              , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS            },    .unit = "flags" },
-            { "karaoke"             , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE           },    .unit = "flags" },
-            { "forced"              , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED            },    .unit = "flags" },
-            { "hearing_impaired"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED  },    .unit = "flags" },
-            { "visual_impaired"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED   },    .unit = "flags" },
-            { "clean_effects"       , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS     },    .unit = "flags" },
-            { "attached_pic"        , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC      },    .unit = "flags" },
-            { "captions"            , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS          },    .unit = "flags" },
-            { "descriptions"        , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS      },    .unit = "flags" },
-            { "dependent"           , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT         },    .unit = "flags" },
-            { "metadata"            , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA          },    .unit = "flags" },
-            { NULL },
-        };
-        static const AVClass class = {
-            .class_name = "",
-            .item_name  = av_default_item_name,
-            .option     = opts,
-            .version    = LIBAVUTIL_VERSION_INT,
-        };
-        const AVClass *pclass = &class;
-
-        ret = av_opt_eval_flags(&pclass, &opts[0], ost->disposition, &ost->st->disposition);
+#if LIBAVFORMAT_VERSION_MAJOR >= 60
+        ret = av_opt_set(ost->st, "disposition", ost->disposition, 0);
+#else
+        {
+            const AVClass *class = av_stream_get_class();
+            const AVOption    *o = av_opt_find(&class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ);
+
+            av_assert0(o);
+            ret = av_opt_eval_flags(&class, o, ost->disposition, &ost->st->disposition);
+        }
+#endif
+
         if (ret < 0)
             return ret;
     }
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 55bc7e2019..a8611f5877 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -722,10 +722,34 @@ void avformat_free_context(AVFormatContext *s)
     av_free(s);
 }
 
+static const AVOption stream_options[] = {
+    { "disposition", NULL, offsetof(AVStream, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 },
+        .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" },
+        { "default",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT           },    .unit = "disposition" },
+        { "dub",                .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB               },    .unit = "disposition" },
+        { "original",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL          },    .unit = "disposition" },
+        { "comment",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT           },    .unit = "disposition" },
+        { "lyrics",             .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS            },    .unit = "disposition" },
+        { "karaoke",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE           },    .unit = "disposition" },
+        { "forced",             .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED            },    .unit = "disposition" },
+        { "hearing_impaired",   .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED  },    .unit = "disposition" },
+        { "visual_impaired",    .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED   },    .unit = "disposition" },
+        { "clean_effects",      .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS     },    .unit = "disposition" },
+        { "attached_pic",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC      },    .unit = "disposition" },
+        { "timed_thumbnails",   .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS  },    .unit = "disposition" },
+        { "captions",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS          },    .unit = "disposition" },
+        { "descriptions",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS      },    .unit = "disposition" },
+        { "metadata",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA          },    .unit = "disposition" },
+        { "dependent",          .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT         },    .unit = "disposition" },
+        { "still_image",        .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE       },    .unit = "disposition" },
+    { NULL }
+};
+
 static const AVClass stream_class = {
     .class_name     = "AVStream",
     .item_name      = av_default_item_name,
     .version        = LIBAVUTIL_VERSION_INT,
+    .option         = stream_options,
 };
 
 const AVClass *av_stream_get_class(void)



More information about the ffmpeg-cvslog mailing list