summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorrcombs <rcombs@rcombs.me>2023-01-28 14:19:17 -0600
committerJan Ekström <jeebjp@gmail.com>2023-03-14 22:32:40 +0200
commit0da0acdae8e729eecfb2498ac11cb86a7fe3360d (patch)
tree6bd51c6b7aa4db090c4ebbd68391b71e30e75d13 /demux
parent3eb2dfe2eb782327daf7f5e567bf4f791bc578b8 (diff)
downloadmpv-0da0acdae8e729eecfb2498ac11cb86a7fe3360d.tar.bz2
mpv-0da0acdae8e729eecfb2498ac11cb86a7fe3360d.tar.xz
demux_mkv: support ARIB captions
Diffstat (limited to 'demux')
-rw-r--r--demux/demux_mkv.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 3f0472dae9..c330709d23 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -1831,9 +1831,15 @@ static const char *const mkv_sub_tag[][2] = {
{ "D_WEBVTT/CAPTIONS", "webvtt-webm"},
{ "S_TEXT/WEBVTT", "webvtt"},
{ "S_DVBSUB", "dvb_subtitle"},
+ { "S_ARIBSUB", "arib_caption"},
{0}
};
+static void avcodec_par_destructor(void *p)
+{
+ avcodec_parameters_free(p);
+}
+
static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track)
{
const char *subtitle_type = NULL;
@@ -1862,6 +1868,38 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track)
sh->codec->extradata = track->private_data;
sh->codec->extradata_size = track->private_size;
+ if (!strcmp(sh->codec->codec, "arib_caption") && track->private_size >= 3) {
+ struct AVCodecParameters **lavp = talloc_ptrtype(track, lavp);
+
+ talloc_set_destructor(lavp, avcodec_par_destructor);
+
+ struct AVCodecParameters *lav = *lavp = sh->codec->lav_codecpar = avcodec_parameters_alloc();
+ MP_HANDLE_OOM(lav);
+
+ lav->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ lav->codec_id = AV_CODEC_ID_ARIB_CAPTION;
+
+ int component_tag = track->private_data[0];
+ int data_component_id = AV_RB16(track->private_data + 1);
+ switch (data_component_id) {
+ case 0x0008:
+ // [0x30..0x37] are component tags utilized for
+ // non-mobile captioning service ("profile A").
+ if (component_tag >= 0x30 && component_tag <= 0x37)
+ lav->profile = FF_PROFILE_ARIB_PROFILE_A;
+ break;
+ case 0x0012:
+ // component tag 0x87 signifies a mobile/partial reception
+ // (1seg) captioning service ("profile C").
+ if (component_tag == 0x87)
+ lav->profile = FF_PROFILE_ARIB_PROFILE_C;
+ break;
+ }
+ if (lav->profile == FF_PROFILE_UNKNOWN)
+ MP_WARN(demuxer, "ARIB caption profile %02x / %04x not supported.\n",
+ component_tag, data_component_id);
+ }
+
demux_add_sh_stream(demuxer, sh);
if (!subtitle_type)