[FFmpeg-devel] [PATCH 4/4] mpegtsenc: handle audio channel specific language metadata

Anssi Hannula anssi.hannula
Sat Feb 12 19:24:41 CET 2011


---
 libavformat/mpegtsenc.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index a9e381e..c5cb836 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -283,7 +283,33 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
         /* write optional descriptors here */
         switch(st->codec->codec_type) {
         case AVMEDIA_TYPE_AUDIO:
-            if (lang && strlen(lang->value) == 3) {
+            {
+                AVMetadataTag *ch_lang = av_metadata_get(st->metadata, "channel0/language", NULL, 0);
+                if (ch_lang && strlen(ch_lang->value) == 3) {
+                    /* add channel specific tags */
+                    uint8_t* lang_len_ptr;
+                    int ch;
+                    char *language_key = av_strdup("channel0/language");
+                    if (!language_key)
+                        break;
+                    *q++ = 0x0a; /* ISO 639 language descriptor */
+                    lang_len_ptr = q++;
+                    for (ch = 0; ch <= 9; ch++) {
+                        if (ch > 0) {
+                            language_key[7] = '0' + ch;
+                            ch_lang = av_metadata_get(st->metadata, language_key, NULL, 0);
+                            if (!ch_lang || strlen(ch_lang->value) != 3)
+                                break;
+                        }
+                        *q++ = ch_lang->value[0];
+                        *q++ = ch_lang->value[1];
+                        *q++ = ch_lang->value[2];
+                        *q++ = 0; /* undefined type */
+                    }
+                    *lang_len_ptr = ch * 4;
+                    av_freep(&language_key);
+                }
+            else if (lang && strlen(lang->value) == 3) {
                 *q++ = 0x0a; /* ISO 639 language descriptor */
                 *q++ = 4;
                 *q++ = lang->value[0];
@@ -298,6 +324,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                 else
                 *q++ = 0; /* undefined type */
             }
+            }
             break;
         case AVMEDIA_TYPE_SUBTITLE:
             {
-- 
1.7.3




More information about the ffmpeg-devel mailing list