diff options
author | davidfstr <[email protected]> | 2011-03-30 02:50:42 +0000 |
---|---|---|
committer | davidfstr <[email protected]> | 2011-03-30 02:50:42 +0000 |
commit | d5efaf404899a7b3738bae7bd7910066bf7ff4e6 (patch) | |
tree | 6ac85261fe0e2c49fd6bb0187bff0f10abe37cb3 /libhb/muxmp4.c | |
parent | 1e1036dce8643fbc707aef29772f13b5deaab7a8 (diff) |
MP4 muxer ignores all but the first of overlapping UTF-8 subtitles.
This is necessary because MP4 does not support overlapping subtitles. Attempting to use overlapping subtitles causes the display of subsequent subtitles to be delayed incorrectly.
Subsequent patches may merge UTF-8 subtitles (upstream) so that this case does not occur.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3890 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/muxmp4.c')
-rw-r--r-- | libhb/muxmp4.c | 113 |
1 files changed, 62 insertions, 51 deletions
diff --git a/libhb/muxmp4.c b/libhb/muxmp4.c index 19a14a0b1..e206f3c13 100644 --- a/libhb/muxmp4.c +++ b/libhb/muxmp4.c @@ -1107,64 +1107,75 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, { if( mux_data->sub_format == TEXTSUB ) { - /* Write an empty sample */ - if ( mux_data->sum_dur < buf->start ) + /* MPEG4 timed text does not allow overlapping samples; upstream + code should coalesce overlapping subtitle lines. */ + if( buf->start < mux_data->sum_dur ) { - uint8_t empty[2] = {0,0}; + hb_log("MP4Mux: skipping overlapping subtitle, " + "start %"PRId64", stop %"PRId64", sum_dur %"PRId64, + buf->start, buf->stop, m->sum_dur); + } + else + { + /* Write an empty sample */ + if ( mux_data->sum_dur < buf->start ) + { + uint8_t empty[2] = {0,0}; + if( !MP4WriteSample( m->file, + mux_data->track, + empty, + 2, + buf->start - mux_data->sum_dur, + 0, + 1 )) + { + hb_error("Failed to write to output file, disk full?"); + *job->die = 1; + } + mux_data->sum_dur += buf->start - mux_data->sum_dur; + } + uint8_t styleatom[2048];; + uint16_t stylesize = 0; + uint8_t buffer[2048]; + uint16_t buffersize = 0; + uint8_t output[2048]; + + *buffer = '\0'; + + /* + * Copy the subtitle into buffer stripping markup and creating + * style atoms for them. + */ + hb_muxmp4_process_subtitle_style( buf->data, + buffer, + styleatom, &stylesize ); + + buffersize = strlen((char*)buffer); + + hb_deep_log(3, "MuxMP4:Sub:%fs:%"PRId64":%"PRId64":%"PRId64": %s", + (float)buf->start / 90000, buf->start, buf->stop, + (buf->stop - buf->start), buffer); + + /* Write the subtitle sample */ + memcpy( output + 2, buffer, buffersize ); + memcpy( output + 2 + buffersize, styleatom, stylesize); + output[0] = ( buffersize >> 8 ) & 0xff; + output[1] = buffersize & 0xff; + if( !MP4WriteSample( m->file, - mux_data->track, - empty, - 2, - buf->start - mux_data->sum_dur, - 0, - 1 )) + mux_data->track, + output, + buffersize + stylesize + 2, + buf->stop - buf->start, + 0, + 1 )) { hb_error("Failed to write to output file, disk full?"); *job->die = 1; - } - mux_data->sum_dur += buf->start - mux_data->sum_dur; - } - uint8_t styleatom[2048];; - uint16_t stylesize = 0; - uint8_t buffer[2048]; - uint16_t buffersize = 0; - uint8_t output[2048]; - - *buffer = '\0'; - - /* - * Copy the subtitle into buffer stripping markup and creating - * style atoms for them. - */ - hb_muxmp4_process_subtitle_style( buf->data, - buffer, - styleatom, &stylesize ); - - buffersize = strlen((char*)buffer); - - hb_deep_log(3, "MuxMP4:Sub:%fs:%"PRId64":%"PRId64":%"PRId64": %s", - (float)buf->start / 90000, buf->start, buf->stop, - (buf->stop - buf->start), buffer); - - /* Write the subtitle sample */ - memcpy( output + 2, buffer, buffersize ); - memcpy( output + 2 + buffersize, styleatom, stylesize); - output[0] = ( buffersize >> 8 ) & 0xff; - output[1] = buffersize & 0xff; + } - if( !MP4WriteSample( m->file, - mux_data->track, - output, - buffersize + stylesize + 2, - buf->stop - buf->start, - 0, - 1 )) - { - hb_error("Failed to write to output file, disk full?"); - *job->die = 1; + mux_data->sum_dur += (buf->stop - buf->start); } - - mux_data->sum_dur += (buf->stop - buf->start); } else if( mux_data->sub_format == PICTURESUB ) { |