diff mbox series

[FFmpeg-devel,v4] avformat/mpegtsenc: enable muxing of ARIB captions

Message ID 20210607170952.8944-1-jeebjp@gmail.com
State Accepted
Commit f38458089f28df73a7badf459117d668ce988ca6
Headers show
Series [FFmpeg-devel,v4] avformat/mpegtsenc: enable muxing of ARIB captions | expand

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

Jan Ekström June 7, 2021, 5:09 p.m. UTC
From: zheng qian <xqq@xqq.im>

Writes a general ARIB stream identifier descriptor, as well
as a data component descriptor which also includes a
pre-defined additional_arib_caption_info structure.

Signed-off-by: zheng qian <xqq@xqq.im>
---
 libavformat/mpegtsenc.c | 48 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

Comments

Jan Ekström June 7, 2021, 5:21 p.m. UTC | #1
On Mon, Jun 7, 2021 at 8:09 PM Jan Ekström <jeebjp@gmail.com> wrote:
>
> From: zheng qian <xqq@xqq.im>
>
> Writes a general ARIB stream identifier descriptor, as well
> as a data component descriptor which also includes a
> pre-defined additional_arib_caption_info structure.
>
> Signed-off-by: zheng qian <xqq@xqq.im>
> ---

For the record, I did and do think that counting and limiting the
amount of ARIB caption streams per program would be technically more
correct, but since:
1. In most cases you will only have a single stream in your input of a
given profile (as multi-language subtitles are supposed to be handled
in the same PID).
2. it seems like a pain as mpegtsenc does not have existing
infrastructure for these sorts of checks as nothing else is limited in
stream count per-program.

I decided that utilizing the default identifier (0x30, 0x87) for all
such streams is Good Enough for an initial implementation. For Profile
A streams values are available until 0x37, but effectively only
permitted for secondary renditions (multi-view etc). Profile C only
permits a single identifier - 0x87.

As changes compared to v3:

1. I have split the descriptor writing into its own function, as
mpegts_write_pmt is already long enough.
2. Checked references and adjusted some comments as well as the commit message.

Jan
zheng qian June 7, 2021, 11:37 p.m. UTC | #2
On Tue, Jun 8, 2021 at 2:28 AM Jan Ekström <jeebjp@gmail.com> wrote:
>
> On Mon, Jun 7, 2021 at 8:09 PM Jan Ekström <jeebjp@gmail.com> wrote:
> >
> > From: zheng qian <xqq@xqq.im>
> >
> > Writes a general ARIB stream identifier descriptor, as well
> > as a data component descriptor which also includes a
> > pre-defined additional_arib_caption_info structure.
> >
> > Signed-off-by: zheng qian <xqq@xqq.im>
> > ---
>
> For the record, I did and do think that counting and limiting the
> amount of ARIB caption streams per program would be technically more
> correct, but since:
> 1. In most cases you will only have a single stream in your input of a
> given profile (as multi-language subtitles are supposed to be handled
> in the same PID).
> 2. it seems like a pain as mpegtsenc does not have existing
> infrastructure for these sorts of checks as nothing else is limited in
> stream count per-program.
>
> I decided that utilizing the default identifier (0x30, 0x87) for all
> such streams is Good Enough for an initial implementation. For Profile
> A streams values are available until 0x37, but effectively only
> permitted for secondary renditions (multi-view etc). Profile C only
> permits a single identifier - 0x87.
>
> As changes compared to v3:
>
> 1. I have split the descriptor writing into its own function, as
> mpegts_write_pmt is already long enough.
> 2. Checked references and adjusted some comments as well as the commit message.
>
> Jan

LGTM.

Regards,
zheng qian

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Jan Ekström June 10, 2021, 8:28 p.m. UTC | #3
On Mon, Jun 7, 2021 at 8:09 PM Jan Ekström <jeebjp@gmail.com> wrote:
>
> From: zheng qian <xqq@xqq.im>
>
> Writes a general ARIB stream identifier descriptor, as well
> as a data component descriptor which also includes a
> pre-defined additional_arib_caption_info structure.
>
> Signed-off-by: zheng qian <xqq@xqq.im>
> ---

Applied as f38458089f28df73a7badf459117d668ce988ca6

Jan
diff mbox series

Patch

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 04af6da2db..98dac17994 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -287,6 +287,50 @@  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)
+{
+    uint8_t stream_identifier;
+    uint16_t data_component_id;
+    uint8_t *q = *q_ptr;
+
+    switch (codecpar->profile) {
+    case FF_PROFILE_ARIB_PROFILE_A:
+        stream_identifier = 0x30;
+        data_component_id = 0x0008;
+        break;
+    case FF_PROFILE_ARIB_PROFILE_C:
+        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);
+        return AVERROR_INVALIDDATA;
+    }
+
+    // stream_identifier_descriptor
+    *q++ = 0x52;  // descriptor_tag
+    *q++ = 1;     // descriptor_length
+    *q++ = stream_identifier;  // component_tag: stream_identifier
+
+    // data_component_descriptor, defined in ARIB STD-B10, part 2, 6.2.20
+    *q++ = 0xFD;  // descriptor_tag: ARIB data coding type descriptor
+    *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,
+    // 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')
+
+    *q_ptr = q;
+
+    return 0;
+}
+
 static void put_registration_descriptor(uint8_t **q_ptr, uint32_t tag)
 {
     uint8_t *q = *q_ptr;
@@ -369,6 +413,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:
@@ -726,6 +771,9 @@  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)
+                    break;
             }
         break;
         case AVMEDIA_TYPE_VIDEO: