diff options
author | Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk> | 2012-09-07 17:38:18 +0200 |
---|---|---|
committer | Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk> | 2012-09-07 17:38:40 +0200 |
commit | 839e75d5d145d486a5c114f8f9f7ea362d12866f (patch) | |
tree | 4a7454f641b15f753ad73c1bd36c242971b85f8f /ext | |
parent | 67342c46b660da36e840a6293835925b6763c064 (diff) |
x264enc: handle possibly negative DTS provided by codec
... by arranging for an offset such that DTS == PTS for keyframes,
which is expected elsewhere to go along with semantics of PTS and DTS.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=679443
Diffstat (limited to 'ext')
-rw-r--r-- | ext/x264/gstx264enc.c | 23 | ||||
-rw-r--r-- | ext/x264/gstx264enc.h | 1 |
2 files changed, 20 insertions, 4 deletions
diff --git a/ext/x264/gstx264enc.c b/ext/x264/gstx264enc.c index 217065d1..59ee1d3a 100644 --- a/ext/x264/gstx264enc.c +++ b/ext/x264/gstx264enc.c @@ -1170,6 +1170,8 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder) } encoder->reconfig = FALSE; + /* good start, will be corrected if needed */ + encoder->dts_offset = 0; GST_OBJECT_UNLOCK (encoder); @@ -1699,11 +1701,24 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in, "output: dts %" G_GINT64_FORMAT " pts %" G_GINT64_FORMAT, (gint64) pic_out.i_dts, (gint64) pic_out.i_pts); - if (pic_out.i_dts < 0) + /* we want to know if x264 is messing around with this */ + g_assert (frame->pts == pic_out.i_pts); + if (pic_out.b_keyframe) { + /* expect dts == pts, and also positive ts, + * so arrange for an offset if needed */ + if (pic_out.i_dts + encoder->dts_offset != pic_out.i_pts) { + encoder->dts_offset = pic_out.i_pts - pic_out.i_dts; + GST_DEBUG_OBJECT (encoder, "determined dts offset %" G_GINT64_FORMAT, + encoder->dts_offset); + } + } + + frame->dts = pic_out.i_dts + encoder->dts_offset; + /* should be ok now, surprise if not */ + if (frame->dts < 0) { + GST_WARNING_OBJECT (encoder, "negative dts after offset compensation"); frame->dts = GST_CLOCK_TIME_NONE; - else - frame->dts = pic_out.i_dts; - frame->pts = pic_out.i_pts; + } if (pic_out.b_keyframe) { GST_INFO ("Output keyframe"); diff --git a/ext/x264/gstx264enc.h b/ext/x264/gstx264enc.h index 0cf2e553..725cff0f 100644 --- a/ext/x264/gstx264enc.h +++ b/ext/x264/gstx264enc.h @@ -51,6 +51,7 @@ struct _GstX264Enc x264_t *x264enc; x264_param_t x264param; gint current_byte_stream; + GstClockTime dts_offset; /* List of frame/buffer mapping structs for * pending frames */ |