Webrtc到GStreamer管道导致非严格单调PTS错误

juud5qan  于 2023-03-12  发布在  其他
关注(0)|答案(1)|浏览(168)

我是Gstreamer框架的新手,真的需要这个问题的帮助。我正在尝试将webrtc视频从浏览器网络摄像头流到后端系统,我想在后端系统捕获和处理webrtc视频(忽略音频)。当浏览器和后端在同一个系统上时没有问题。当浏览器和后端通过互联网通信时会出现问题。以下是我的Gstream管道线:

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

后端仅捕获第一帧,之后将抛出以下警告:

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

我还尝试重新标记帧的时间,但没有成功。
如果有人能指导我如何解决这个问题,我将非常感激。

vaqhlq81

vaqhlq811#

通过使用标识元素重新标记帧的时间戳,设法修复了该问题,如下所示:

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

从管道获取标识元素并注册回调:

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);
}

最后重新标记帧

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);
}

相关问题