x264enc: Use gst_video_encoder_set_min_pts
authorMatej Knopp <matej.knopp@gmail.com>
Wed, 26 Nov 2014 21:15:43 +0000 (22:15 +0100)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 11 Jun 2015 14:29:25 +0000 (10:29 -0400)
This method replace the manual adjustment of PTS and DTS to avoid
negative DTS issues. Using this method will also update the segment so
we don't loos sync.

https://bugzilla.gnome.org/show_bug.cgi?id=740575

ext/x264/gstx264enc.c
ext/x264/gstx264enc.h

index d619b8e..7d5e2b4 100644 (file)
@@ -1164,6 +1164,10 @@ gst_x264_enc_start (GstVideoEncoder * encoder)
 
   x264enc->current_byte_stream = GST_X264_ENC_STREAM_FORMAT_FROM_PROPERTY;
 
+  /* make sure that we have enough time for first DTS,
+     this is probably overkill for most streams */
+  gst_video_encoder_set_min_pts (encoder, GST_SECOND * 60 * 60 * 1000);
+
   return TRUE;
 }
 
@@ -1539,8 +1543,6 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
       encoder->x264param.i_frame_packing);
 
   encoder->reconfig = FALSE;
-  /* good start, will be corrected if needed */
-  encoder->ts_offset = 0;
 
   GST_OBJECT_UNLOCK (encoder);
 
@@ -2186,15 +2188,8 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in,
   /* we want to know if x264 is messing around with this */
   g_assert (frame->pts == pic_out.i_pts);
 
-  /* As upstream often starts with PTS set to zero, in presence of b-frames,
-   * x264 will have to use negative DTS. As this is not supported by
-   * GStreamer, we shift both DTS and PTS forward to make it positive. It's
-   * important to shift both in order to ensure PTS remains >= to DTS. */
-  if (pic_out.i_dts < encoder->ts_offset)
-    encoder->ts_offset = pic_out.i_dts;
-
-  frame->dts = pic_out.i_dts - encoder->ts_offset;
-  frame->pts = pic_out.i_pts - encoder->ts_offset;
+  frame->dts = pic_out.i_dts;
+  frame->pts = pic_out.i_pts;
 
   if (pic_out.b_keyframe) {
     GST_DEBUG_OBJECT (encoder, "Output keyframe");
index b7179c8..d1135d9 100644 (file)
@@ -51,7 +51,6 @@ struct _GstX264Enc
   x264_t *x264enc;
   x264_param_t x264param;
   gint current_byte_stream;
-  gint64 ts_offset;
 
   /* List of frame/buffer mapping structs for
    * pending frames */