[FFmpeg-devel] [PATCH] avformat: add a disposition field to AVStreamGroup

James Almer jamrial at gmail.com
Sun Feb 11 01:09:02 EET 2024


The existing (and upcoming) available group types are meant to combine several
streams for presentation, with the result being treated as if it was a stream
itself.
For example, a file could export two stream groups of the same type with one of
them as the "default".

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/avformat.h |  8 +++++
 libavformat/dump.c     | 77 ++++++++++++++++++++++--------------------
 libavformat/options.c  | 45 ++++++++++++------------
 3 files changed, 73 insertions(+), 57 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 5d0fe82250..931c274879 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1093,6 +1093,14 @@ typedef struct AVStreamGroup {
      * Freed by libavformat in avformat_free_context().
      */
     AVStream **streams;
+
+    /**
+     * Stream group disposition - a combination of AV_DISPOSITION_* flags.
+     * - demuxing: set by libavformat when creating the group or in
+     *             avformat_find_stream_info().
+     * - muxing: may be set by the caller before avformat_write_header().
+     */
+    int disposition;
 } AVStreamGroup;
 
 struct AVCodecParserContext *av_stream_get_parser(const AVStream *s);
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 9d37179bb7..c72d7840c1 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -538,6 +538,46 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent,
     }
 }
 
+static void dump_disposition(int disposition, int log_level)
+{
+    if (disposition & AV_DISPOSITION_DEFAULT)
+        av_log(NULL, log_level, " (default)");
+    if (disposition & AV_DISPOSITION_DUB)
+        av_log(NULL, log_level, " (dub)");
+    if (disposition & AV_DISPOSITION_ORIGINAL)
+        av_log(NULL, log_level, " (original)");
+    if (disposition & AV_DISPOSITION_COMMENT)
+        av_log(NULL, log_level, " (comment)");
+    if (disposition & AV_DISPOSITION_LYRICS)
+        av_log(NULL, log_level, " (lyrics)");
+    if (disposition & AV_DISPOSITION_KARAOKE)
+        av_log(NULL, log_level, " (karaoke)");
+    if (disposition & AV_DISPOSITION_FORCED)
+        av_log(NULL, log_level, " (forced)");
+    if (disposition & AV_DISPOSITION_HEARING_IMPAIRED)
+        av_log(NULL, log_level, " (hearing impaired)");
+    if (disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
+        av_log(NULL, log_level, " (visual impaired)");
+    if (disposition & AV_DISPOSITION_CLEAN_EFFECTS)
+        av_log(NULL, log_level, " (clean effects)");
+    if (disposition & AV_DISPOSITION_ATTACHED_PIC)
+        av_log(NULL, log_level, " (attached pic)");
+    if (disposition & AV_DISPOSITION_TIMED_THUMBNAILS)
+        av_log(NULL, log_level, " (timed thumbnails)");
+    if (disposition & AV_DISPOSITION_CAPTIONS)
+        av_log(NULL, log_level, " (captions)");
+    if (disposition & AV_DISPOSITION_DESCRIPTIONS)
+        av_log(NULL, log_level, " (descriptions)");
+    if (disposition & AV_DISPOSITION_METADATA)
+        av_log(NULL, log_level, " (metadata)");
+    if (disposition & AV_DISPOSITION_DEPENDENT)
+        av_log(NULL, log_level, " (dependent)");
+    if (disposition & AV_DISPOSITION_STILL_IMAGE)
+        av_log(NULL, log_level, " (still image)");
+    if (disposition & AV_DISPOSITION_NON_DIEGETIC)
+        av_log(NULL, log_level, " (non-diegetic)");
+}
+
 /* "user interface" functions */
 static void dump_stream_format(const AVFormatContext *ic, int i,
                                int group_index, int index, int is_output,
@@ -620,42 +660,7 @@ static void dump_stream_format(const AVFormatContext *ic, int i,
             print_fps(1 / av_q2d(st->time_base), "tbn", log_level);
     }
 
-    if (st->disposition & AV_DISPOSITION_DEFAULT)
-        av_log(NULL, log_level, " (default)");
-    if (st->disposition & AV_DISPOSITION_DUB)
-        av_log(NULL, log_level, " (dub)");
-    if (st->disposition & AV_DISPOSITION_ORIGINAL)
-        av_log(NULL, log_level, " (original)");
-    if (st->disposition & AV_DISPOSITION_COMMENT)
-        av_log(NULL, log_level, " (comment)");
-    if (st->disposition & AV_DISPOSITION_LYRICS)
-        av_log(NULL, log_level, " (lyrics)");
-    if (st->disposition & AV_DISPOSITION_KARAOKE)
-        av_log(NULL, log_level, " (karaoke)");
-    if (st->disposition & AV_DISPOSITION_FORCED)
-        av_log(NULL, log_level, " (forced)");
-    if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
-        av_log(NULL, log_level, " (hearing impaired)");
-    if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
-        av_log(NULL, log_level, " (visual impaired)");
-    if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
-        av_log(NULL, log_level, " (clean effects)");
-    if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
-        av_log(NULL, log_level, " (attached pic)");
-    if (st->disposition & AV_DISPOSITION_TIMED_THUMBNAILS)
-        av_log(NULL, log_level, " (timed thumbnails)");
-    if (st->disposition & AV_DISPOSITION_CAPTIONS)
-        av_log(NULL, log_level, " (captions)");
-    if (st->disposition & AV_DISPOSITION_DESCRIPTIONS)
-        av_log(NULL, log_level, " (descriptions)");
-    if (st->disposition & AV_DISPOSITION_METADATA)
-        av_log(NULL, log_level, " (metadata)");
-    if (st->disposition & AV_DISPOSITION_DEPENDENT)
-        av_log(NULL, log_level, " (dependent)");
-    if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
-        av_log(NULL, log_level, " (still image)");
-    if (st->disposition & AV_DISPOSITION_NON_DIEGETIC)
-        av_log(NULL, log_level, " (non-diegetic)");
+    dump_disposition(st->disposition, log_level);
     av_log(NULL, log_level, "\n");
 
     dump_metadata(NULL, st->metadata, extra_indent, log_level);
diff --git a/libavformat/options.c b/libavformat/options.c
index 03e6a2a7ff..f54a3c97b5 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -208,28 +208,30 @@ const AVClass *avformat_get_class(void)
     return &av_format_context_class;
 }
 
-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" },
-        { "non_diegetic",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_NON_DIEGETIC      },    .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" },
+#define DISPOSITION_OPT(ctx)                                                                                                        \
+    { "disposition", NULL, offsetof(ctx, 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" }, \
+        { "non_diegetic",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_NON_DIEGETIC      },    .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" }
 
+static const AVOption stream_options[] = {
+    DISPOSITION_OPT(AVStream),
     { "discard", NULL, offsetof(AVStream, discard), AV_OPT_TYPE_INT, { .i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX,
         .flags = AV_OPT_FLAG_DECODING_PARAM, .unit = "avdiscard" },
         { "none",               .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONE     }, .unit = "avdiscard" },
@@ -380,6 +382,7 @@ static const AVClass *stream_group_child_iterate(void **opaque)
 }
 
 static const AVOption stream_group_options[] = {
+    DISPOSITION_OPT(AVStreamGroup),
     {"id", "Set group id", offsetof(AVStreamGroup, id), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM },
     { NULL }
 };
-- 
2.43.0



More information about the ffmpeg-devel mailing list