From 22bc107543d6f06d31f4d43f5529c86ceb8862b8 Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Mon, 20 Sep 2010 13:10:13 +0400 Subject: [PATCH] Fix DTS calculation if the first PTS wasn't zero --- common/common.h | 1 + encoder/encoder.c | 13 +++++++++---- x264.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/common.h b/common/common.h index efb25be..132cfee 100644 --- a/common/common.h +++ b/common/common.h @@ -499,6 +499,7 @@ struct x264_t int i_delay; /* Number of frames buffered for B reordering */ int i_bframe_delay; int64_t i_bframe_delay_time; + int64_t i_first_pts; int64_t i_init_delta; int64_t i_prev_reordered_pts[2]; int64_t i_largest_pts; diff --git a/encoder/encoder.c b/encoder/encoder.c index fa4401b..cd95180 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -2329,8 +2329,13 @@ int x264_encoder_encode( x264_t *h, fenc->i_frame = h->frames.i_input++; - if( h->frames.i_bframe_delay && fenc->i_frame == h->frames.i_bframe_delay ) - h->frames.i_bframe_delay_time = fenc->i_pts; + if( h->frames.i_bframe_delay ) + { + if ( fenc->i_frame == 0 ) + h->frames.i_first_pts = fenc->i_pts; + if ( fenc->i_frame == h->frames.i_bframe_delay ) + h->frames.i_bframe_delay_time = fenc->i_pts - h->frames.i_first_pts; + } if( h->param.b_vfr_input && fenc->i_pts <= h->frames.i_largest_pts ) x264_log( h, X264_LOG_WARNING, "non-strictly-monotonic PTS\n" ); @@ -2495,8 +2500,8 @@ int x264_encoder_encode( x264_t *h, { /* DTS compression */ if( h->i_frame == 1 ) - thread_current->frames.i_init_delta = h->fenc->i_reordered_pts * h->i_dts_compress_multiplier; - h->fdec->i_dts = h->i_frame * thread_current->frames.i_init_delta / h->i_dts_compress_multiplier; + thread_current->frames.i_init_delta = (h->fenc->i_reordered_pts - h->frames.i_first_pts) * h->i_dts_compress_multiplier; + h->fdec->i_dts = h->i_frame * thread_current->frames.i_init_delta / h->i_dts_compress_multiplier + h->frames.i_first_pts * h->i_dts_compress_multiplier; } } else diff --git a/x264.h b/x264.h index 8174015..71f5f55 100644 --- a/x264.h +++ b/x264.h @@ -653,7 +653,7 @@ typedef struct int b_keyframe; /* In: user pts, Out: pts of encoded picture (user)*/ int64_t i_pts; - /* Out: frame dts. Since the pts of the first frame is always zero, + /* Out: frame dts. When the pts of the first frame is close to zero, * initial frames may have a negative dts which must be dealt with by any muxer */ int64_t i_dts; /* In: custom encoding parameters to be set from this frame forwards -- 1.6.1.9.g97c34