From aff9ec05b85f01a5e9e864ab81ae6af344013c1b Mon Sep 17 00:00:00 2001 From: Rodeo Date: Sun, 30 Jun 2013 15:38:59 +0000 Subject: [PATCH] QSV: enc_qsv: write initial PTS-DTS delay. Some muxers (e.g. MP4) expect this value to be set. git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/qsv@5619 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/enc_qsv.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libhb/enc_qsv.c b/libhb/enc_qsv.c index 20cbb82c6..9f54f15f0 100644 --- a/libhb/enc_qsv.c +++ b/libhb/enc_qsv.c @@ -1049,6 +1049,26 @@ int encqsvWork( hb_work_object_t * w, hb_buffer_t ** buf_in, buf->s.renderOffset = hb_qsv_pop_next_dts(pv->list_dts); } } + + /* + * In the MP4 container, DT(0) = STTS(0) = 0. + * + * Which gives us: + * CT(0) = CTTS(0) + STTS(0) = CTTS(0) = PTS(0) - DTS(0) + * When DTS(0) < PTS(0), we then have: + * CT(0) > 0 for video, but not audio (breaks A/V sync). + * + * This is typically solved by writing an edit list shifting + * video samples by the initial delay, PTS(0) - DTS(0). + * + * See: + * ISO/IEC 14496-12:2008(E), ISO base media file format + * - 8.6.1.2 Decoding Time to Sample Box + */ + if (w->config->h264.init_delay == 0 && buf->s.renderOffset < 0) + { + w->config->h264.init_delay = -buf->s.renderOffset; + } } if(pv->qsv_config.gop_ref_dist > 1) -- 2.40.0