[FFmpeg-devel] [PATCH v3 3/4] avformat/mpegtsenc: Add muxing support for ARIB superimpose stream

zheng qian xqq at xqq.im
Sat Jul 17 05:38:28 EEST 2021


Signed-off-by: zheng qian <xqq at xqq.im>
---
 libavformat/mpegtsenc.c | 40 +++++++++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 98dac17994..b5d2938c4a 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -287,26 +287,37 @@ static void putbuf(uint8_t **q_ptr, const uint8_t *buf, size_t len)
     *q_ptr += len;
 }
 
-static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr,
-                                       AVCodecParameters *codecpar)
+static int put_arib_descriptor(AVFormatContext *s, AVStream* st, uint8_t **q_ptr)
 {
     uint8_t stream_identifier;
     uint16_t data_component_id;
     uint8_t *q = *q_ptr;
 
-    switch (codecpar->profile) {
+    switch (st->codecpar->profile) {
     case FF_PROFILE_ARIB_PROFILE_A:
-        stream_identifier = 0x30;
+        if (st->disposition & AV_DISPOSITION_URGENT) {
+            // ARIB superimpose, with AV_DISPOSITION_URGENT flag
+            stream_identifier = 0x38;
+        } else {
+            // ARIB caption
+            stream_identifier = 0x30;
+        }
         data_component_id = 0x0008;
         break;
     case FF_PROFILE_ARIB_PROFILE_C:
-        stream_identifier = 0x87;
+        if (st->disposition & AV_DISPOSITION_URGENT) {
+            // ARIB superimpose
+            stream_identifier = 0x88;
+        } else {
+            // ARIB caption
+            stream_identifier = 0x87;
+        }
         data_component_id = 0x0012;
         break;
     default:
         av_log(s, AV_LOG_ERROR,
                "Unset/unknown ARIB caption profile %d utilized!\n",
-               codecpar->profile);
+               st->codecpar->profile);
         return AVERROR_INVALIDDATA;
     }
 
@@ -320,11 +331,17 @@ static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr,
     *q++ = 3;     // descriptor_length
     put16(&q, data_component_id);  // data_component_id
     // additional_arib_caption_info: defined in ARIB STD-B24, fascicle 1, Part 3, 9.6.1
-    // Here we utilize a pre-defined set of values defined in ARIB TR-B14,
+    // Here we utilize pre-defined sets of values defined in ARIB TR-B14,
     // Fascicle 2, 4.2.8.5 for PMT usage, with the reserved bits in the middle
     // set to 1 (as that is what every broadcaster seems to be doing in
     // production).
-    *q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+    if (st->disposition & AV_DISPOSITION_URGENT) {
+        // ARIB superimpose
+        *q++ = 0x3C; // DMF('0011'), Reserved('11'), Timing('00')
+    } else {
+        // ARIB caption
+        *q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+    }
 
     *q_ptr = q;
 
@@ -772,7 +789,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
 
                *len_ptr = q - len_ptr - 1;
             } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) {
-                if (put_arib_caption_descriptor(s, &q, st->codecpar) < 0)
+                if (put_arib_descriptor(s, st, &q) < 0)
                     break;
             }
         break;
@@ -1444,6 +1461,11 @@ static int get_pes_stream_id(AVFormatContext *s, AVStream *st, int stream_id, in
         if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous KLV */
             *async = 1;
         return stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM;
+    } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
+               st->codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION &&
+               st->disposition & AV_DISPOSITION_URGENT) {  // ARIB superimpose
+        // ARIB TR-B14, Fascicle 1 (2/2), Vol.3, 4.2.3
+        return STREAM_ID_PRIVATE_STREAM_2;
     } else {
         return STREAM_ID_PRIVATE_STREAM_1;
     }
-- 
2.29.2



More information about the ffmpeg-devel mailing list