msdkenc: Set pts at handle_frame

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3998>
This commit is contained in:
Mengkejiergeli Ba 2023-02-15 17:16:47 +08:00 committed by Haihao Xiang
parent 8d7cab1f0d
commit 28e2eccf55
2 changed files with 20 additions and 0 deletions

View file

@ -690,6 +690,15 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz)
thiz->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE; thiz->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
thiz->param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420; thiz->param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
/* work-around to avoid zero fps in msdk structure */
if (0 == thiz->param.mfx.FrameInfo.FrameRateExtN)
thiz->param.mfx.FrameInfo.FrameRateExtN = 30;
thiz->frame_duration =
gst_util_uint64_scale (GST_SECOND,
thiz->param.mfx.FrameInfo.FrameRateExtN,
thiz->param.mfx.FrameInfo.FrameRateExtD);
switch (encoder_input_fmt) { switch (encoder_input_fmt) {
case GST_VIDEO_FORMAT_P010_10LE: case GST_VIDEO_FORMAT_P010_10LE:
thiz->param.mfx.FrameInfo.FourCC = MFX_FOURCC_P010; thiz->param.mfx.FrameInfo.FourCC = MFX_FOURCC_P010;
@ -1870,7 +1879,15 @@ gst_msdkenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame)
fdata->frame_surface = surface; 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->presentation_frame_number == 0)
thiz->start_pts = frame->pts;
if (frame->pts != GST_CLOCK_TIME_NONE) { if (frame->pts != GST_CLOCK_TIME_NONE) {
frame->pts = thiz->start_pts +
frame->presentation_frame_number * thiz->frame_duration;
frame->duration = thiz->frame_duration;
surface->surface->Data.TimeStamp = surface->surface->Data.TimeStamp =
gst_util_uint64_scale (frame->pts, 90000, GST_SECOND); gst_util_uint64_scale (frame->pts, 90000, GST_SECOND);
} else { } else {

View file

@ -167,6 +167,9 @@ struct _GstMsdkEnc
guint max_frame_size_p; guint max_frame_size_p;
gint16 lowdelay_brc; gint16 lowdelay_brc;
GstClockTime start_pts;
GstClockTime frame_duration;
GstStructure *ext_coding_props; GstStructure *ext_coding_props;
gboolean reconfig; gboolean reconfig;