diff mbox series

[FFmpeg-devel,v1,2/2] libavformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption

Message ID 20210406081816.54105-2-xqq@xqq.im
State New
Headers show
Series [FFmpeg-devel,v1,1/2] libavformat/mpegts: Extract arib_caption descriptor data into codecpar->extradata
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

zheng qian April 6, 2021, 8:18 a.m. UTC
Stream copy for arib_caption into mpegts is not working correctly for now.

This patch utilizes the data stored in codecpar->extradata to write necessary
stream_identifier_descriptor and data_component_descriptor into PMT table
for arib_caption remuxing.

This patch fixes the copying of arib_caption. After this patch, arib_caption
inside the outputted (remuxed) mpegts stream can be recognized correctly
as an arib_caption subtitle stream.

Signed-off-by: zheng qian <xqq@xqq.im>
---
 libavformat/mpegtsenc.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index a357f3a6aa..e26a5d3b51 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -357,6 +357,7 @@  static int get_dvb_stream_type(AVFormatContext *s, AVStream *st)
         break;
     case AV_CODEC_ID_DVB_SUBTITLE:
     case AV_CODEC_ID_DVB_TELETEXT:
+    case AV_CODEC_ID_ARIB_CAPTION:
         stream_type = STREAM_TYPE_PRIVATE_DATA;
         break;
     case AV_CODEC_ID_SMPTE_KLV:
@@ -714,8 +715,21 @@  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 (st->codecpar->extradata && st->codecpar->extradata_size >= 4) {
+                    // stream_identifier_descriptor
+                    *q++ = 0x52;  // descriptor_tag
+                    *q++ = 1;     // descriptor_length
+                    *q++ = st->codecpar->extradata[0];  // component_tag: stream_identifier
+
+                    // data_component_descriptor
+                    *q++ = 0xFD;  // descriptor_tag: ARIB data coding type descriptor
+                    *q++ = 3;     // descriptor_length
+                    memcpy(q, &st->codecpar->extradata[1], 3);  // data_component_id & additional_arib_caption_info
+                    q += 3;
+                }
             }
-        break;
+            break;
         case AVMEDIA_TYPE_VIDEO:
             if (stream_type == STREAM_TYPE_VIDEO_DIRAC) {
                 put_registration_descriptor(&q, MKTAG('d', 'r', 'a', 'c'));