Commit 8c260b2c authored by François Cartegnie's avatar François Cartegnie 🤞

demux: mp4: add basic WebVTT support

parent 87777f04
......@@ -120,8 +120,7 @@ Demuxers:
* Support raw h265/hevc files
* Support multi-channel WAV without channel-maps
* Rewrite MKV seeking
* Rewrite of TTML demuxer
* Support for TTML in ISOBMF/MP4 and DASH
* Support for TTML and WebVTT in ISOBMF/MP4 and DASH
* Fix Quicktime Mp4 inside MKV and unpacketized VC1
Stream filter:
......
......@@ -1177,7 +1177,10 @@ int SetupSpuES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
case VLC_FOURCC('s','t','p','p'):
p_track->fmt.i_codec = VLC_CODEC_TTML;
break;
case ATOM_wvtt:
p_track->fmt.i_codec = VLC_CODEC_SUBT;
p_track->fmt.i_original_fourcc = ATOM_wvtt;
break;
case ATOM_c608: /* EIA608 closed captions */
//case ATOM_c708: /* EIA708 closed captions */
p_track->fmt.i_codec = VLC_CODEC_EIA608_1;
......
......@@ -4257,6 +4257,9 @@ static const struct
{ ATOM_tx3g, MP4_ReadBox_sample_tx3g, 0 },
{ ATOM_c608, MP4_ReadBox_sample_clcp, ATOM_stsd },
//{ ATOM_text, MP4_ReadBox_sample_text, 0 },
/* In sample WebVTT subtitle atoms. No ATOM_wvtt in normal parsing */
{ ATOM_vttc, MP4_ReadBoxContainer, ATOM_wvtt },
{ ATOM_payl, MP4_ReadBox_Binary, ATOM_vttc },
/* for codecs */
{ ATOM_soun, MP4_ReadBox_sample_soun, ATOM_stsd },
......
......@@ -288,6 +288,11 @@ typedef int64_t stime_t;
#define ATOM_clcp VLC_FOURCC( 'c', 'l', 'c', 'p' )
#define ATOM_c608 VLC_FOURCC( 'c', '6', '0', '8' )
#define ATOM_c708 VLC_FOURCC( 'c', '7', '0', '8' )
#define ATOM_wvtt VLC_FOURCC( 'w', 'v', 't', 't' )
/* In sample for WebVTT */
#define ATOM_vttc VLC_FOURCC( 'v', 't', 't', 'c' )
#define ATOM_payl VLC_FOURCC( 'p', 'a', 'y', 'l' )
#define ATOM_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' )
#define ATOM_0xa9aut VLC_FOURCC( 0xa9, 'a', 'u', 't' )
......
......@@ -380,6 +380,38 @@ static int AllocateTracks( demux_t *p_demux, unsigned i_tracks )
return VLC_SUCCESS;
}
static block_t * MP4_WebVTT_Convert( demux_t *p_demux, block_t * p_block )
{
stream_t *p_stream =
vlc_stream_MemoryNew( p_demux, p_block->p_buffer,
p_block->i_buffer, true );
if( p_stream )
{
MP4_Box_t *p_vroot = MP4_BoxNew(ATOM_wvtt);
if( p_vroot )
{
p_vroot->i_size = p_block->i_buffer;
if ( MP4_ReadBoxContainerChildren( p_stream, p_vroot, NULL ) == 1 )
{
MP4_Box_t *p_payl = MP4_BoxGet( p_vroot, "vttc/payl" );
if( p_payl && p_payl->i_size >= 9 )
{
p_block->p_buffer += p_payl->i_pos + 8;
p_block->i_buffer = p_payl->i_size - 8;
p_block->p_buffer[p_block->i_buffer - 1] = '\0';
}
else p_block->i_buffer = 0;
#ifndef NDEBUG
MP4_BoxDumpStructure(p_stream, p_vroot);
#endif
}
MP4_BoxFree(p_vroot);
}
vlc_stream_Delete( p_stream );
}
return p_block;
}
static block_t * MP4_EIA608_Convert( block_t * p_block )
{
/* Rebuild codec data from encap */
......@@ -527,6 +559,10 @@ static block_t * MP4_Block_Convert( demux_t *p_demux, const mp4_track_t *p_track
case VLC_CODEC_EIA608_1:
p_block = MP4_EIA608_Convert( p_block );
break;
case VLC_CODEC_SUBT:
if( p_track->fmt.i_original_fourcc == ATOM_wvtt )
p_block = MP4_WebVTT_Convert( p_demux, p_block );
break;
default:
p_block->i_buffer = 0;
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment