demux_mkv: support ARIB captions

This commit is contained in:
rcombs 2023-01-28 14:19:17 -06:00 committed by Jan Ekström
parent 3eb2dfe2eb
commit 0da0acdae8
1 changed files with 38 additions and 0 deletions

View File

@ -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)