[FFmpeg-cvslog] mpegts muxer: DVB subtitles multiple languages support

mrlika git at videolan.org
Thu Feb 13 13:50:42 CET 2014


ffmpeg | branch: master | mrlika <andriy.lysnevych at gmail.com> | Thu Feb 13 02:00:24 2014 +0200| [af786236cc61405e8d284e716c5ec2539316a1ad] | committer: Michael Niedermayer

mpegts muxer: DVB subtitles multiple languages support

* restore multiple languages data from extradata to PMT table
* setting correctly hearing empaired subtitling type

Reviewed-by: Marton Balint <cus at passwd.hu>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=af786236cc61405e8d284e716c5ec2539316a1ad
---

 libavformat/mpegtsenc.c |   49 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 13 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 9b42e48..40ff85b 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -377,20 +377,43 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                 const char *language = lang && strlen(lang->value) >= 3 ? lang->value : default_language;
 
                 if (st->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
-                    /* The descriptor tag. subtitling_descriptor */
-                    *q++ = 0x59;
-                    *q++ = 8;
-                    *q++ = language[0];
-                    *q++ = language[1];
-                    *q++ = language[2];
-                    *q++ = 0x10; /* normal subtitles (0x20 = if hearing pb) */
-                    if(st->codec->extradata_size == 4) {
-                        memcpy(q, st->codec->extradata, 4);
-                        q += 4;
-                    } else {
-                        put16(&q, 1); /* page id */
-                        put16(&q, 1); /* ancillary page id */
+                    uint8_t *len_ptr;
+                    int extradata_copied = 0;
+
+                    *q++ = 0x59; /* subtitling_descriptor */
+                    len_ptr = q++;
+
+                    while (strlen(language) >= 3 && (sizeof(data) - (q - data)) >= 8) { /* 8 bytes per DVB subtitle substream data */
+                        *q++ = *language++;
+                        *q++ = *language++;
+                        *q++ = *language++;
+                        /* Skip comma */
+                        if (*language != '\0')
+                            language++;
+
+                        if (st->codec->extradata_size - extradata_copied >= 5) {
+                            *q++ = st->codec->extradata[extradata_copied + 4]; /* subtitling_type */
+                            memcpy(q, st->codec->extradata + extradata_copied, 4); /* composition_page_id and ancillary_page_id */
+                            extradata_copied += 5;
+                            q += 4;
+                        } else {
+                            /* subtitling_type:
+                             * 0x10 - normal with no monitor aspect ratio criticality
+                             * 0x20 - for the hard of hearing with no monitor aspect ratio criticality */
+                            *q++ = (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED) ? 0x20 : 0x10;
+                            if ((st->codec->extradata_size == 4) && (extradata_copied == 0)) {
+                                /* support of old 4-byte extradata format */
+                                memcpy(q, st->codec->extradata, 4); /* composition_page_id and ancillary_page_id */
+                                extradata_copied += 4;
+                                q += 4;
+                            } else {
+                                put16(&q, 1); /* composition_page_id */
+                                put16(&q, 1); /* ancillary_page_id */
+                            }
+                        }
                     }
+
+                    *len_ptr = q - len_ptr - 1;
                 } else if (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT) {
                     uint8_t *len_ptr = NULL;
                     int extradata_copied = 0;



More information about the ffmpeg-cvslog mailing list