Signed-off-by: Peter Große <pe...@friiks.de>
---
 libavformat/dashenc.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index c561ad1..a0c7811 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -460,10 +460,19 @@ static int write_adaptation_set(AVFormatContext *s, 
AVIOContext *out, int as_ind
 {
     DASHContext *c = s->priv_data;
     AdaptationSet *as = &c->as[as_index];
+    AVDictionaryEntry *lang, *role;
     int i;
 
-    avio_printf(out, "\t\t<AdaptationSet id=\"%s\" contentType=\"%s\" 
segmentAlignment=\"true\" bitstreamSwitching=\"true\">\n",
+    avio_printf(out, "\t\t<AdaptationSet id=\"%s\" contentType=\"%s\" 
segmentAlignment=\"true\" bitstreamSwitching=\"true\"",
                 as->id, as->media_type == AVMEDIA_TYPE_VIDEO ? "video" : 
"audio");
+    lang = av_dict_get(as->metadata, "language", NULL, 0);
+    if (lang)
+        avio_printf(out, " lang=\"%s\"", lang->value);
+    avio_printf(out, ">\n");
+
+    role = av_dict_get(as->metadata, "role", NULL, 0);
+    if (role)
+        avio_printf(out, "\t\t\t<Role schemeIdUri=\"urn:mpeg:dash:role:2011\" 
value=\"%s\"/>\n", role->value);
 
     for (i = 0; i < s->nb_streams; i++) {
         OutputStream *os = &c->streams[i];
@@ -669,6 +678,14 @@ static int write_manifest(AVFormatContext *s, int final)
     return ff_rename(temp_filename, s->filename);
 }
 
+static int dict_copy_entry(AVDictionary **dst, const AVDictionary *src, const 
char *key)
+{
+    AVDictionaryEntry *entry = av_dict_get(src, key, NULL, 0);
+    if (entry)
+        av_dict_set(dst, key, entry->value, AV_DICT_DONT_OVERWRITE);
+    return 0;
+}
+
 static int dash_write_header(AVFormatContext *s)
 {
     DASHContext *c = s->priv_data;
@@ -713,6 +730,7 @@ static int dash_write_header(AVFormatContext *s)
 
     for (i = 0; i < s->nb_streams; i++) {
         OutputStream *os = &c->streams[i];
+        AdaptationSet *as = &c->as[os->as_idx - 1];
         AVFormatContext *ctx;
         AVStream *st;
         AVDictionary *opts = NULL;
@@ -743,6 +761,10 @@ static int dash_write_header(AVFormatContext *s)
             }
         }
 
+        // copy AdaptationSet language and role from stream metadata
+        dict_copy_entry(&as->metadata, s->streams[i]->metadata, "language");
+        dict_copy_entry(&as->metadata, s->streams[i]->metadata, "role");
+
         ctx = avformat_alloc_context();
         if (!ctx) {
             ret = AVERROR(ENOMEM);
-- 
2.10.2

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to