diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c index 2b225ebaf68..563e3d1476e 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c @@ -679,6 +679,10 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz) thiz->param.mfx.NumRefFrame = thiz->ref_frames; thiz->param.mfx.EncodedOrder = 0; /* Take input frames in display order */ + /* WA in the case of zero framerate, we set framerate as 30/1 */ + if (info->fps_n == 0) + info->fps_n = 30; + thiz->param.mfx.FrameInfo.Width = GST_ROUND_UP_16 (info->width); thiz->param.mfx.FrameInfo.Height = GST_ROUND_UP_32 (info->height); thiz->param.mfx.FrameInfo.CropW = info->width; @@ -690,6 +694,9 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz) thiz->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE; thiz->param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420; + thiz->frame_duration = gst_util_uint64_scale (GST_SECOND, info->fps_d, + info->fps_n); + switch (encoder_input_fmt) { case GST_VIDEO_FORMAT_P010_10LE: thiz->param.mfx.FrameInfo.FourCC = MFX_FOURCC_P010; @@ -1870,7 +1877,15 @@ gst_msdkenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame) fdata->frame_surface = surface; + /* It is possible to have input frame without any framerate/pts info, + * we need to set the correct pts here. */ + if (frame->system_frame_number == 0) + thiz->start_pts = frame->pts; + if (frame->pts != GST_CLOCK_TIME_NONE) { + frame->pts = + thiz->start_pts + frame->system_frame_number * thiz->frame_duration; + frame->duration = thiz->frame_duration; surface->surface->Data.TimeStamp = gst_util_uint64_scale (frame->pts, 90000, GST_SECOND); } else { diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h index e54d8b010b9..52b79c86363 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h @@ -167,6 +167,9 @@ struct _GstMsdkEnc guint max_frame_size_p; gint16 lowdelay_brc; + GstClockTime start_pts; + GstClockTime frame_duration; + GstStructure *ext_coding_props; gboolean reconfig;