Skip to content

Commit

Permalink
msdkenc: Set pts at handle_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
mengker33 committed Feb 16, 2023
1 parent f7c2602 commit 94920ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 94920ea

Please sign in to comment.