Skip to content

Instantly share code, notes, and snippets.

@henry0312
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henry0312/b0feccedd5b9fd2e636b to your computer and use it in GitHub Desktop.
Save henry0312/b0feccedd5b9fd2e636b to your computer and use it in GitHub Desktop.
ARIB subtitles for libavformat
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d39e7f1..b9533f2 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -522,6 +522,8 @@ enum AVCodecID {
AV_CODEC_ID_VPLAYER = MKBETAG('V','P','l','r'),
AV_CODEC_ID_PJS = MKBETAG('P','h','J','S'),
AV_CODEC_ID_ASS = MKBETAG('A','S','S',' '), ///< ASS as defined in Matroska
+ AV_CODEC_ID_ARIB_SUB_A = MKBETAG('A','R','B','A'),
+ AV_CODEC_ID_ARIB_SUB_C = MKBETAG('A','R','B','C'),
/* other specific kind of codecs (generally used for attachments) */
AV_CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 9e9728b..ea1c276 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2662,6 +2662,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("WebVTT subtitle"),
.props = AV_CODEC_PROP_TEXT_SUB,
},
+ {
+ .id = AV_CODEC_ID_ARIB_SUB_A,
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .name = "arib_sub (A)",
+ .long_name = NULL_IF_CONFIG_SMALL("ARIB subtitles: Profile A"),
+ .props = AV_CODEC_PROP_TEXT_SUB,
+ },
+ {
+ .id = AV_CODEC_ID_ARIB_SUB_C,
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .name = "arib_sub (C)",
+ .long_name = NULL_IF_CONFIG_SMALL("ARIB subtitles: Profile C"),
+ .props = AV_CODEC_PROP_TEXT_SUB,
+ },
/* other kind of codecs and pseudo-codecs */
{
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a118689..d3eb3ed 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -649,6 +649,8 @@ static const StreamType ISO_types[] = {
{ 0x02, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG2VIDEO },
{ 0x03, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_MP3 },
{ 0x04, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_MP3 },
+ { 0x06, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_ARIB_SUB_A },
+ { 0x06, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_ARIB_SUB_C },
{ 0x0f, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AAC },
{ 0x10, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG4 },
/* Makito encoder sets stream type 0x11 for AAC,
@@ -1861,6 +1863,40 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
pes->sub_st->index);
pes->sub_st->codec->codec_tag = st->codec->codec_tag;
}
+
+ /*
+ * ARIB Subtitles
+ *
+ * @see 4.2.8.3 Stream format identification in ARIB TR-B14
+ * @see 6.2.7.3 Stream format identification in ARIB TR-B14
+ * @see 6.2.16 Stream identifier descriptor in Part 2 in ARIB STD-B10
+ */
+ if (stream_type == 0x06) {
+ // check component_tag in Stream identifier descriptor
+ switch (st->stream_identifier - 1) {
+ case 0x30:
+ case 0x31:
+ case 0x32:
+ case 0x33:
+ case 0x34:
+ case 0x35:
+ case 0x36:
+ case 0x37:
+ // @see 4.2.8.1 Operation of component tags in ARIB TR-B14
+ st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ st->codec->codec_id = AV_CODEC_ID_ARIB_SUB_A;
+ break;
+ case 0x87:
+ // @see 6.2.7.1 Operation of component tags in ARIB TR-B14
+ st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ st->codec->codec_id = AV_CODEC_ID_ARIB_SUB_C;
+ break;
+ default:
+ st->codec->codec_type = AVMEDIA_TYPE_UNKNOWN;
+ st->codec->codec_id = AV_CODEC_ID_NONE;
+ break;
+ }
+ }
}
p = desc_list_end;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment