Farooq Zaman
Farooq Zaman

Reputation: 505

Webrtc to GStreamer pipeline cause non-strictly-monotonic PTS error

I am new to Gstreamer framework and really need help with this issue. I am trying to stream webrtc video from browser webcam to backend system whereby I want to capture and process webrtc video (ignore audio). There's no issue when browser and backend are on the same system. Problem happens when browser and backend are communicating via internet. Following is my Gstream piple line:

appsrc name=appsrc-video is-live=true ! decodebin ! queue ! x264enc tune=zerolatency ! mp4mux ! filesink location=video-output.mp4

Backend captures only first frame and after that it throws following warnings:

0:00:14.171956087 14019 0x55cc9f24d700 WARN                 x264enc gstx264enc.c:1273:gst_x264_enc_log_callback:<x264enc0> non-strictly-monotonic PTS
0:00:14.208353982 14019 0x55cc9f24d700 WARN                 x264enc gstx264enc.c:1273:gst_x264_enc_log_callback:<x264enc0> non-strictly-monotonic PTS
0:00:14.252514623 14019 0x55cc9f24d700 WARN                 x264enc gstx264enc.c:1273:gst_x264_enc_log_callback:<x264enc0> non-strictly-monotonic PTS
0:00:14.284089147 14019 0x55cc9f24d700 WARN                 x264enc gstx264enc.c:1273:gst_x264_enc_log_callback:<x264enc0> non-strictly-monotonic PTS
0:00:15.280078036 14019 0x55cc9f24d700 WARN                 x264enc gstx264enc.c:1273:gst_x264_enc_log_callback:<x264enc0> non-strictly-monotonic PTS
0:00:15.281438688 14019 0x55cc9f24d700 WARN                 x264enc gstx264enc.c:1273:gst_x264_enc_log_callback:<x264enc0> non-strictly-monotonic PTS

I also tried re-timestamping the frames but no success.

Highly appreciate if someone could guide me on how to resolve this issue.

Upvotes: 1

Views: 394

Answers (1)

Farooq Zaman
Farooq Zaman

Reputation: 505

Managed to fix the issue by retimestamping the frame using identity element as follows:

appsrc name=appsrc-video ! h264parse ! queue max-size-buffers=1000 leaky=downstream ! identity name=\"identity-elem\" signal-handoffs=TRUE ! mpegtsmux ! hlssink location=/tmp/hls/segment_%05d.ts playlist-location=/tmp/hls/playlist.m3u8 target-duration=300

Get identity element from pipeline and register a callback:

GstElement* identity_elem = gst_bin_get_by_name(GST_BIN(pipeline), "identity-elem");
if (identity_elem != NULL) {
    g_object_set(G_OBJECT(identity_elem), "signal-handoffs", TRUE, NULL);
    g_signal_connect(identity_elem, "handoff", G_CALLBACK(cb_identity_handoff), (gpointer) pSampleStreamingSession);
}

and finally retimestamp the frames

GstFlowReturn cb_identity_handoff(GstElement* identity, GstBuffer* buffer, UINT64 trackid)
{
    int fps = 30; // In my case the FPS is 30

    // printf("Retime stamping\n");
    buffer = gst_buffer_make_writable(buffer);

    ptimestamp += gst_util_uint64_scale_int(1, GST_SECOND, fps);
    GST_BUFFER_PTS(buffer) = ptimestamp;
    GST_BUFFER_DTS(buffer) = ptimestamp;

    GST_BUFFER_DURATION(buffer) = gst_util_uint64_scale_int(1, GST_SECOND, fps);
}

Upvotes: 1

Related Questions