diff options
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/common.h | 3 | ||||
-rw-r--r-- | libhb/muxmp4.c | 61 | ||||
-rw-r--r-- | libhb/sync.c | 72 | ||||
-rw-r--r-- | libhb/work.c | 1 |
4 files changed, 91 insertions, 46 deletions
diff --git a/libhb/common.h b/libhb/common.h index 6a2c8d51d..81877d6d2 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -455,7 +455,8 @@ struct hb_subtitle_s #ifdef __LIBHB__ /* Internal data */ hb_fifo_t * fifo_in; /* SPU ES */ - hb_fifo_t * fifo_raw; /* Decodec SPU */ + hb_fifo_t * fifo_raw; /* Decoded SPU */ + hb_fifo_t * fifo_out; /* Correct Timestamps, ready to be muxed */ #endif }; diff --git a/libhb/muxmp4.c b/libhb/muxmp4.c index 81ee2f8ad..bdeea8c42 100644 --- a/libhb/muxmp4.c +++ b/libhb/muxmp4.c @@ -437,6 +437,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, hb_job_t * job = m->job; int64_t duration; int64_t offset = 0; + int i; if( mux_data == job->mux_data ) { @@ -583,6 +584,34 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, } } + for( i = 0; i < hb_list_count( job->list_subtitle ); i++ ) + { + hb_subtitle_t *subtitle = hb_list_item( job->list_subtitle, i ); + + if( subtitle && subtitle->format == TEXTSUB && + subtitle->dest == PASSTHRUSUB ) + { + /* + * Should be adding this one if the timestamp is right. + */ + hb_buffer_t *sub; + + while( ( sub = hb_fifo_see( subtitle->fifo_out )) != NULL ) + { + if (sub->start < buf->start ) { + sub = hb_fifo_get( subtitle->fifo_out ); + hb_log("MuxMP4: Text Sub:%lld: %s", sub->start, sub->data); + hb_buffer_close( &sub ); + } else { + /* + * Not time yet + */ + break; + } + } + } + } + return 0; } @@ -590,7 +619,6 @@ static int MP4End( hb_mux_object_t * m ) { hb_job_t * job = m->job; hb_title_t * title = job->title; - int i; /* Write our final chapter marker */ if( m->job->chapter_markers ) @@ -667,37 +695,6 @@ static int MP4End( hb_mux_object_t * m ) MP4TagsFree( tags ); } - /* - * Display any text subs. - * - * This is placeholder code, what needs to happen is that we need to - * convert these PTS (which are pre-sync ones) into HB timestamps, - * I guess sync should do that? - * - * And then this needs to move into the Mux code above and insert - * subtitle samples into the MP4 at the correct times. - */ - for( i = 0; i < hb_list_count( job->list_subtitle ); i++ ) - { - hb_subtitle_t *subtitle = hb_list_item( job->list_subtitle, i ); - - if( subtitle && subtitle->format == TEXTSUB && - subtitle->dest == PASSTHRUSUB ) - { - /* - * Should be adding this one if the timestamp is right. - */ - hb_buffer_t *buffer; - - while( (buffer = hb_fifo_get( subtitle->fifo_raw )) != NULL ) - { - hb_log("MuxMP4: Text Sub: %s", buffer->data); - - hb_buffer_close( &buffer ); - } - } - } - MP4Close( m->file ); if ( job->mp4_optimize ) diff --git a/libhb/sync.c b/libhb/sync.c index 798c01b26..b102b49f7 100644 --- a/libhb/sync.c +++ b/libhb/sync.c @@ -394,7 +394,39 @@ static void SyncVideo( hb_work_object_t * w ) for( i = 0; i < hb_list_count( job->list_subtitle ); i++) { subtitle = hb_list_item( job->list_subtitle, i ); - if( subtitle->dest == RENDERSUB ) + + /* + * Rewrite timestamps on subtitles that need it (on raw queue). + */ + if( subtitle->source == CCSUB ) + { + /* + * Rewrite timestamps on subtitles that came from Closed Captions + * since they are using the MPEG2 timestamps. + */ + while( ( sub = hb_fifo_see( subtitle->fifo_raw ) ) ) + { + /* + * Rewrite the timestamps as and when the video + * (cur->start) reaches the same timestamp as a + * closed caption (sub->start). + * + * What about discontinuity boundaries - not delt + * with here - Van? + */ + if( sub->start < cur->start ) + { + sub = hb_fifo_get( subtitle->fifo_raw ); + sub->start = pv->next_start; + hb_fifo_push( subtitle->fifo_out, sub ); + } else { + sub = NULL; + break; + } + } + } + + if( subtitle->source == VOBSUB ) { hb_buffer_t * sub2; while( ( sub = hb_fifo_see( subtitle->fifo_raw ) ) ) @@ -528,11 +560,7 @@ static void SyncVideo( hb_work_object_t * w ) if( sub ) { /* - * Don't overwrite the current sub, we'll check the - * other subtitle streams on the next video buffer. - * - * It doesn't make much sense having multiple rendered - * subtitle tracks anyway. + * Got a sub to display... */ break; } @@ -575,14 +603,32 @@ static void SyncVideo( hb_work_object_t * w ) /* If we have a subtitle for this picture, copy it */ /* FIXME: we should avoid this memcpy */ - if( sub ) + if( sub && subtitle && + subtitle->format == PICTURESUB ) { - buf_tmp->sub = hb_buffer_init( sub->size ); - buf_tmp->sub->x = sub->x; - buf_tmp->sub->y = sub->y; - buf_tmp->sub->width = sub->width; - buf_tmp->sub->height = sub->height; - memcpy( buf_tmp->sub->data, sub->data, sub->size ); + if( subtitle->dest == RENDERSUB ) + { + /* + * Tack onto the video buffer for rendering + */ + buf_tmp->sub = hb_buffer_init( sub->size ); + buf_tmp->sub->x = sub->x; + buf_tmp->sub->y = sub->y; + buf_tmp->sub->width = sub->width; + buf_tmp->sub->height = sub->height; + memcpy( buf_tmp->sub->data, sub->data, sub->size ); + } else { + /* + * Pass-Through, pop it off of the raw queue, rewrite times and + * make it available to be muxed. + */ + uint64_t sub_duration; + sub = hb_fifo_get( subtitle->fifo_raw ); + sub_duration = sub->stop - sub->start; + sub->start = buf_tmp->start; + sub->stop = sub->start + duration; + hb_fifo_push( subtitle->fifo_out, sub ); + } } /* Push the frame to the renderer */ diff --git a/libhb/work.c b/libhb/work.c index b413c78fe..6159caf03 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -490,6 +490,7 @@ static void do_job( hb_job_t * job, int cpu_count ) { subtitle->fifo_in = hb_fifo_init( FIFO_CPU_MULT * cpu_count ); subtitle->fifo_raw = hb_fifo_init( FIFO_CPU_MULT * cpu_count ); + subtitle->fifo_out = hb_fifo_init( FIFO_CPU_MULT * cpu_count ); /* * Disable forced subtitles if we didn't find any in the scan |