[vlc-commits] demux: mp4: add basic WebVTT support
Francois Cartegnie
git at videolan.org
Tue Jan 24 19:00:39 CET 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jan 24 18:58:57 2017 +0100| [8c260b2ccdfedf9e19cf6684f49322a57cc0c9d2] | committer: Francois Cartegnie
demux: mp4: add basic WebVTT support
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8c260b2ccdfedf9e19cf6684f49322a57cc0c9d2
---
NEWS | 3 +--
modules/demux/mp4/essetup.c | 5 ++++-
modules/demux/mp4/libmp4.c | 3 +++
modules/demux/mp4/libmp4.h | 5 +++++
modules/demux/mp4/mp4.c | 36 ++++++++++++++++++++++++++++++++++++
5 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index 9a3b91e..8c684c6 100644
--- a/NEWS
+++ b/NEWS
@@ -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:
diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index 9de3100..1cc7b88 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -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;
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 133f77f..01f480a 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -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 },
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index b513e01..fdccec1 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -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' )
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 54084a9..1d396df 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -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;
More information about the vlc-commits
mailing list