[PATCH 4/6] mpegtsenc: handle audio_type metadata

Anssi Hannula anssi.hannula
Fri Jul 16 03:56:13 CEST 2010


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

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index d8f88e5..d92711e 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -199,6 +199,19 @@ static void mpegts_write_pat(AVFormatContext *s)
                           data, q - data);
 }
 
+static uint8_t mpegts_get_audio_type(AVMetadataTag *tag)
+{
+    if (!tag)
+        return 0x00;
+    if (!strcmp(tag->value, "clean effects"))
+        return 0x01;
+    if (!strcmp(tag->value, "hearing impaired"))
+        return 0x02;
+    if (!strcmp(tag->value, "visual impaired"))
+        return 0x03;
+    return 0x00;
+}
+
 static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
 {
     //    MpegTSWrite *ts = s->priv_data;
@@ -262,15 +275,24 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                 if (ch_lang && strlen(ch_lang->value) == 3) {
                     /* add channel specific tags */
                     uint8_t* lang_len_ptr;
-                    char *language_key = av_strdup("channel0/language");
+                    char *language_key;
+                    char *audio_type_key;
                     int ch;
+
+                    language_key = av_strdup("channel0/language");
                     if (!language_key)
                         break;
+                    audio_type_key = av_strdup("channel0/audio_type");
+                    if (!audio_type_key) {
+                        av_freep(&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;
+                            language_key[7] = audio_type_key[7] = '0' + ch;
                             ch_lang = av_metadata_get(st->metadata, language_key, NULL, 0);
                             if (!ch_lang || strlen(ch_lang->value) != 3)
                                 break;
@@ -278,17 +300,20 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                         *q++ = ch_lang->value[0];
                         *q++ = ch_lang->value[1];
                         *q++ = ch_lang->value[2];
-                        *q++ = 0; /* undefined type */
+                        *q++ = mpegts_get_audio_type(av_metadata_get(st->metadata,
+                                                                     audio_type_key, NULL, 0));
                     }
                     *lang_len_ptr = ch * 4;
                     av_freep(&language_key);
+                    av_freep(&audio_type_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 */
+                    *q++ = mpegts_get_audio_type(av_metadata_get(st->metadata,
+                                                                "audio_type", NULL, 0));
                 }
             }
             break;
-- 
1.7.1


--Boundary-00=_ZzOQMxVxT486NZ+
Content-Type: text/plain;
  charset="iso-8859-15";
  name="0005-ffplay-add-support-for-selecting-a-single-audio-chan.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
	filename="0005-ffplay-add-support-for-selecting-a-single-audio-chan.patch"




More information about the ffmpeg-devel mailing list