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

Anssi Hannula anssi.hannula
Mon Feb 14 19:43:42 CET 2011


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

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 6945b4b..dac0e4e 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