[PATCH 3/6] mpegtsenc: handle audio channel specific language metadata

Anssi Hannula anssi.hannula
Fri Jul 16 03:43:58 CEST 2010


---
 libavformat/mpegtsenc.c |   40 +++++++++++++++++++++++++++++++++-------
 1 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 4bd48d3..d8f88e5 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -257,13 +257,39 @@ 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) {
-                *q++ = 0x0a; /* ISO 639 language descriptor */
-                *q++ = 4;
-                *q++ = lang->value[0];
-                *q++ = lang->value[1];
-                *q++ = lang->value[2];
-                *q++ = 0; /* undefined type */
+            {
+                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;
+                    char *language_key = av_strdup("channel0/language");
+                    int ch;
+                    if (!language_key)
+                        break;
+                    *q++ = 0x0a; /* ISO 639 language descriptor */
+                    lang_len_ptr = q++;
+                    for (ch = 0; ch < 10; ch++) {
+                        if (ch) {
+                            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];
+                    *q++ = lang->value[1];
+                    *q++ = lang->value[2];
+                    *q++ = 0; /* undefined type */
+                }
             }
             break;
         case AVMEDIA_TYPE_SUBTITLE:
-- 
1.7.1


--Boundary-00=_ZzOQMxVxT486NZ+
Content-Type: text/plain;
  charset="iso-8859-15";
  name="0004-mpegtsenc-handle-audio_type-metadata.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
	filename="0004-mpegtsenc-handle-audio_type-metadata.patch"




More information about the ffmpeg-devel mailing list