diff options
author | jstebbins <[email protected]> | 2013-11-19 22:46:01 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2013-11-19 22:46:01 +0000 |
commit | 5e4d8c7244a85fafa7ae477f8378a0c56e7ba365 (patch) | |
tree | 72bf0f9f17ad8259862d06c00486cf24c1ed3d10 | |
parent | f0dbe6e2a2af173e60a20da86c78692757e69112 (diff) |
libhb: fix problem with gereration of dts for lavc encoded video
The old method resulted in dts > pts in some cases.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5899 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/encavcodec.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c index a695fa443..580bcd530 100644 --- a/libhb/encavcodec.c +++ b/libhb/encavcodec.c @@ -328,7 +328,7 @@ static void compute_dts_offset( hb_work_private_t * pv, hb_buffer_t * buf ) { if ( pv->job->areBframes ) { - if ( ( pv->frameno_in - 1 ) == pv->job->areBframes ) + if ( ( pv->frameno_in ) == pv->job->areBframes ) { pv->dts_delay = buf->s.start; pv->job->config.h264.init_delay = pv->dts_delay; @@ -370,12 +370,20 @@ static hb_buffer_t * process_delay_list( hb_work_private_t * pv, hb_buffer_t * b // and return all queued buffers. if ( pv->delay_tail == NULL && buf != NULL ) { - pv->frameno_out++; // Use the cached frame info to get the start time of Nth frame // Note that start Nth frame != start time this buffer since the // output buffers have rearranged start times. - int64_t start = get_frame_start( pv, pv->frameno_out ); - buf->s.renderOffset = start - pv->dts_delay; + if (pv->frameno_out < pv->job->areBframes) + { + int64_t start = get_frame_start( pv, pv->frameno_out ); + buf->s.renderOffset = start - pv->dts_delay; + } + else + { + buf->s.renderOffset = + get_frame_start(pv, pv->frameno_out - pv->job->areBframes); + } + pv->frameno_out++; return buf; } else @@ -384,13 +392,21 @@ static hb_buffer_t * process_delay_list( hb_work_private_t * pv, hb_buffer_t * b buf = pv->delay_head; while ( buf ) { - pv->frameno_out++; // Use the cached frame info to get the start time of Nth frame // Note that start Nth frame != start time this buffer since the // output buffers have rearranged start times. - int64_t start = get_frame_start( pv, pv->frameno_out ); - buf->s.renderOffset = start - pv->dts_delay; + if (pv->frameno_out < pv->job->areBframes) + { + int64_t start = get_frame_start( pv, pv->frameno_out ); + buf->s.renderOffset = start - pv->dts_delay; + } + else + { + buf->s.renderOffset = get_frame_start(pv, + pv->frameno_out - pv->job->areBframes); + } buf = buf->next; + pv->frameno_out++; } buf = pv->delay_head; pv->delay_head = pv->delay_tail = NULL; @@ -399,7 +415,7 @@ static hb_buffer_t * process_delay_list( hb_work_private_t * pv, hb_buffer_t * b } else if ( buf ) { - buf->s.renderOffset = buf->s.start - pv->dts_delay; + buf->s.renderOffset = buf->s.start; return buf; } return NULL; @@ -438,17 +454,17 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in, // doesn't do the trick. It must be set in the AVFrame. frame->quality = pv->context->global_quality; - // Bizarro ffmpeg appears to require the input AVFrame.pts to be - // set to a frame number. Setting it to an actual pts causes - // jerky video. - // frame->pts = in->s.start; - frame->pts = ++pv->frameno_in; - // Remember info about this frame that we need to pass across // the avcodec_encode_video call (since it reorders frames). save_frame_info( pv, in ); compute_dts_offset( pv, in ); + // Bizarro ffmpeg appears to require the input AVFrame.pts to be + // set to a frame number. Setting it to an actual pts causes + // jerky video. + // frame->pts = in->s.start; + frame->pts = pv->frameno_in++; + if ( pv->context->codec ) { int ret; |