diff options
author | Rodeo <[email protected]> | 2012-11-21 19:11:09 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2012-11-21 19:11:09 +0000 |
commit | 67c78f708522efcf3ca03842ea5eb669fc372b63 (patch) | |
tree | 672d94e10be1a76251cdc300fe835189c573b1de | |
parent | 5ab9b16a3f9635778f1ea07129560adb1be28cc5 (diff) |
muxmkv: don't write the last chapter marker if it is shorter than 3/2 second.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5075 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/muxmkv.c | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/libhb/muxmkv.c b/libhb/muxmkv.c index 2b629bc49..735bb631e 100644 --- a/libhb/muxmkv.c +++ b/libhb/muxmkv.c @@ -431,45 +431,43 @@ static int MKVInit( hb_mux_object_t * m ) return 0; } -static int MKVMux( hb_mux_object_t * m, hb_mux_data_t * mux_data, - hb_buffer_t * buf ) +static int MKVMux(hb_mux_object_t *m, hb_mux_data_t *mux_data, hb_buffer_t *buf) { - ogg_packet *op = NULL; - hb_job_t * job = m->job; - uint64_t timecode = 0; + char chapter_name[1024]; hb_chapter_t *chapter_data; - char tmp_buffer[1024]; - char *string = tmp_buffer; + uint64_t timecode = 0; + ogg_packet *op = NULL; + hb_job_t *job = m->job; if (mux_data == job->mux_data) { /* Video */ timecode = buf->s.start * TIMECODE_SCALE; - if (job->chapter_markers && (buf->s.new_chap || timecode == 0)) + if (job->chapter_markers && buf->s.new_chap) { - /* Make sure we're not writing a chapter that has 0 length */ - if (mux_data->prev_chapter_tc != timecode) - { - if ( buf->s.new_chap ) - { - mux_data->current_chapter = buf->s.new_chap - 2; - } - chapter_data = hb_list_item( job->list_chapter, - mux_data->current_chapter++ ); - tmp_buffer[0] = '\0'; + // reached chapter N, write marker for chapter N-1 + mux_data->current_chapter = buf->s.new_chap - 1; + + // chapter numbers start at 1, but the list starts at 0 + chapter_data = hb_list_item(job->list_chapter, + mux_data->current_chapter - 1); - if( chapter_data != NULL ) + // make sure we're not writing a chapter that has 0 length + if (chapter_data != NULL && mux_data->prev_chapter_tc < timecode) + { + if (chapter_data->title != NULL) { - string = chapter_data->title; + snprintf(chapter_name, 1023, "%s", chapter_data->title); } - - if( strlen(string) == 0 || strlen(string) >= 1024 ) + else { - snprintf( tmp_buffer, 1023, "Chapter %02i", mux_data->current_chapter ); - string = tmp_buffer; + snprintf(chapter_name, 1023, "Chapter %d", + mux_data->current_chapter); } - mk_createChapterSimple(m->file, mux_data->prev_chapter_tc, mux_data->prev_chapter_tc, string); + mk_createChapterSimple(m->file, + mux_data->prev_chapter_tc, + mux_data->prev_chapter_tc, chapter_name); } mux_data->prev_chapter_tc = timecode; } @@ -550,13 +548,12 @@ static int MKVMux( hb_mux_object_t * m, hb_mux_data_t * mux_data, return 0; } -static int MKVEnd( hb_mux_object_t * m ) +static int MKVEnd(hb_mux_object_t *m) { - hb_job_t *job = m->job; - hb_mux_data_t *mux_data = job->mux_data; + char chapter_name[1024]; hb_chapter_t *chapter_data; - char tmp_buffer[1024]; - char *string = tmp_buffer; + hb_job_t *job = m->job; + hb_mux_data_t *mux_data = job->mux_data; if( !job->mux_data ) { @@ -566,23 +563,28 @@ static int MKVEnd( hb_mux_object_t * m ) return 0; } - chapter_data = hb_list_item( job->list_chapter, mux_data->current_chapter++ ); - - if(job->chapter_markers) + if (job->chapter_markers) { - tmp_buffer[0] = '\0'; - - if( chapter_data != NULL ) - { - string = chapter_data->title; - } + // get the last chapter + chapter_data = hb_list_item(job->list_chapter, + mux_data->current_chapter++); - if( strlen(string) == 0 || strlen(string) >= 1024 ) + // only write the last chapter marker if it lasts at least 1.5 second + if (chapter_data != NULL && chapter_data->duration > 135000LL) { - snprintf( tmp_buffer, 1023, "Chapter %02i", mux_data->current_chapter ); - string = tmp_buffer; + if (chapter_data->title != NULL) + { + snprintf(chapter_name, 1023, "%s", chapter_data->title); + } + else + { + snprintf(chapter_name, 1023, "Chapter %d", + mux_data->current_chapter); + } + mk_createChapterSimple(m->file, + mux_data->prev_chapter_tc, + mux_data->prev_chapter_tc, chapter_name); } - mk_createChapterSimple(m->file, mux_data->prev_chapter_tc, mux_data->prev_chapter_tc, string); } if( job->metadata ) |