Commit fd569c88 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: mp4: add support for tx3g (fix #8305)

parent 6a63bcae
...@@ -49,6 +49,7 @@ Demuxer: ...@@ -49,6 +49,7 @@ Demuxer:
* Fix encoding issues in some XML playlist formats * Fix encoding issues in some XML playlist formats
* Support THP Wii/Gamecube, RenderWare and Escape Replay game video files * Support THP Wii/Gamecube, RenderWare and Escape Replay game video files
* New HEVC raw packetizer and demuxer * New HEVC raw packetizer and demuxer
* Handle MOV/MP4 tx3g styled subtitles through codec
Muxers: Muxers:
* Important rework of the Ogg muxer, notably for skeleton * Important rework of the Ogg muxer, notably for skeleton
......
...@@ -1842,7 +1842,7 @@ static int MP4_ReadBox_sample_text( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1842,7 +1842,7 @@ static int MP4_ReadBox_sample_text( stream_t *p_stream, MP4_Box_t *p_box )
MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[0] ); MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[0] );
MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[1] ); MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[1] );
MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[2] ); MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[2] );
p_box->data.p_sample_text->i_background_color[3] = 0; p_box->data.p_sample_text->i_background_color[3] = 0xFF;
MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_top ); MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_top );
MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_left ); MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_left );
...@@ -1879,6 +1879,13 @@ static int MP4_ReadBox_sample_tx3g( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1879,6 +1879,13 @@ static int MP4_ReadBox_sample_tx3g( stream_t *p_stream, MP4_Box_t *p_box )
MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_bottom ); MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_bottom );
MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_right ); MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_right );
MP4_GET4BYTES( p_box->data.p_sample_text->i_reserved3 );
MP4_GET2BYTES( p_box->data.p_sample_text->i_font_id );
MP4_GET1BYTE ( p_box->data.p_sample_text->i_font_face );
MP4_GET1BYTE ( p_box->data.p_sample_text->i_font_size );
MP4_GET4BYTES( p_box->data.p_sample_text->i_font_color );
#ifdef MP4_VERBOSE #ifdef MP4_VERBOSE
msg_Dbg( p_stream, "read box: \"tx3g\" in stsd text" ); msg_Dbg( p_stream, "read box: \"tx3g\" in stsd text" );
#endif #endif
...@@ -3218,6 +3225,10 @@ static const struct ...@@ -3218,6 +3225,10 @@ static const struct
{ ATOM_free, MP4_ReadBoxSkip, MP4_FreeBox_Common }, { ATOM_free, MP4_ReadBoxSkip, MP4_FreeBox_Common },
{ ATOM_wide, MP4_ReadBoxSkip, MP4_FreeBox_Common }, { ATOM_wide, MP4_ReadBoxSkip, MP4_FreeBox_Common },
/* Subtitles */
{ ATOM_tx3g, MP4_ReadBox_sample_tx3g, MP4_FreeBox_Common },
//{ ATOM_text, MP4_ReadBox_sample_text, MP4_FreeBox_Common },
/* for codecs */ /* for codecs */
{ ATOM_soun, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun }, { ATOM_soun, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun },
{ ATOM_ms02, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun }, { ATOM_ms02, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun },
......
...@@ -580,6 +580,13 @@ typedef struct ...@@ -580,6 +580,13 @@ typedef struct
uint16_t i_text_box_bottom; uint16_t i_text_box_bottom;
uint16_t i_text_box_right; uint16_t i_text_box_right;
uint32_t i_reserved3;
uint16_t i_font_id;
uint8_t i_font_face;
uint8_t i_font_size;
uint32_t i_font_color; //RGBA
// TODO to complete // TODO to complete
} MP4_Box_data_sample_text_t; } MP4_Box_data_sample_text_t;
......
...@@ -756,36 +756,12 @@ static int Demux( demux_t *p_demux ) ...@@ -756,36 +756,12 @@ static int Demux( demux_t *p_demux )
MP4_TrackUnselect( p_demux, tk ); MP4_TrackUnselect( p_demux, tk );
break; break;
} }
else if( tk->fmt.i_cat == SPU_ES ) else if( tk->fmt.i_cat == SPU_ES )
{ {
if( tk->fmt.i_codec == VLC_CODEC_SUBT && if ( tk->fmt.i_codec != VLC_CODEC_TX3G )
p_block->i_buffer >= 2 ) p_block->i_buffer = 0;
{
size_t i_size = GetWBE( p_block->p_buffer );
if( i_size + 2 <= p_block->i_buffer )
{
char *p;
/* remove the length field, and append a '\0' */
memmove( &p_block->p_buffer[0],
&p_block->p_buffer[2], i_size );
p_block->p_buffer[i_size] = '\0';
p_block->i_buffer = i_size + 1;
/* convert \r -> \n */
while( ( p = strchr((char *) p_block->p_buffer, '\r' ) ) )
{
*p = '\n';
}
}
else
{
/* Invalid */
p_block->i_buffer = 0;
}
}
} }
/* dts */ /* dts */
p_block->i_dts = VLC_TS_0 + MP4_TrackGetDTS( p_demux, tk ); p_block->i_dts = VLC_TS_0 + MP4_TrackGetDTS( p_demux, tk );
/* pts */ /* pts */
...@@ -1931,7 +1907,31 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track, ...@@ -1931,7 +1907,31 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
case( VLC_FOURCC( 't', 'e', 'x', 't' ) ): case( VLC_FOURCC( 't', 'e', 'x', 't' ) ):
case( VLC_FOURCC( 't', 'x', '3', 'g' ) ): case( VLC_FOURCC( 't', 'x', '3', 'g' ) ):
p_track->fmt.i_codec = VLC_CODEC_SUBT; {
p_track->fmt.i_codec = VLC_CODEC_TX3G;
MP4_Box_data_sample_text_t *p_text = p_sample->data.p_sample_text;
if ( p_text )
{
text_style_t *p_style = text_style_New();
if ( p_style )
{
if ( p_text->i_font_size ) /* !WARN: % in absolute storage */
p_style->i_font_size = p_text->i_font_size;
if ( p_text->i_font_color )
{
p_style->i_font_color = p_text->i_font_color >> 8;
p_style->i_font_alpha = p_text->i_font_color & 0xFF;
}
if ( p_text->i_background_color )
{
p_style->i_background_color = p_text->i_background_color[0] >> 8;
p_style->i_background_color |= p_text->i_background_color[1] >> 8;
p_style->i_background_color |= p_text->i_background_color[2] >> 8;
p_style->i_background_alpha = p_text->i_background_color[3] >> 8;
}
}
p_track->fmt.subs.p_style = p_style;
}
/* FIXME: Not true, could be UTF-16 with a Byte Order Mark (0xfeff) */ /* FIXME: Not true, could be UTF-16 with a Byte Order Mark (0xfeff) */
/* FIXME UTF-8 doesn't work here ? */ /* FIXME UTF-8 doesn't work here ? */
if( p_track->b_mac_encoding ) if( p_track->b_mac_encoding )
...@@ -1939,7 +1939,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track, ...@@ -1939,7 +1939,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
else else
p_track->fmt.subs.psz_encoding = strdup( "UTF-8" ); p_track->fmt.subs.psz_encoding = strdup( "UTF-8" );
break; break;
}
case VLC_FOURCC('y','v','1','2'): case VLC_FOURCC('y','v','1','2'):
p_track->fmt.i_codec = VLC_CODEC_YV12; p_track->fmt.i_codec = VLC_CODEC_YV12;
break; break;
...@@ -2592,10 +2592,11 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track, ...@@ -2592,10 +2592,11 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
p_track->fmt.i_cat = VIDEO_ES; p_track->fmt.i_cat = VIDEO_ES;
break; break;
case( ATOM_tx3g ):
case( ATOM_text ): case( ATOM_text ):
case( ATOM_subp ): case( ATOM_subp ):
case( ATOM_tx3g ):
case( ATOM_sbtl ): case( ATOM_sbtl ):
p_track->fmt.i_codec = VLC_CODEC_TX3G;
p_track->fmt.i_cat = SPU_ES; p_track->fmt.i_cat = SPU_ES;
break; 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