gpt4 book ai didi

gstreamer - 从 C++ 向 gstreamer 提供视频;如何让时间工作

转载 作者:行者123 更新时间:2023-12-05 05:03:15 24 4
gpt4 key购买 nike

我正在尝试将 gstreamer 管道添加到我的程序中。我的程序生成了一个视频流,我希望 gstreamer 对其进行处理。这基本上是有效的,只是时间不对:显示的每一帧之间存在巨大的延迟。同样在几秒钟后,它完全停止了。

这是启动流的代码:

    GstCaps *video_caps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "RGB",
"width", G_TYPE_INT, w,
"height", G_TYPE_INT, h,
"block", G_TYPE_BOOLEAN, TRUE,
"do-timestamp", G_TYPE_BOOLEAN, TRUE,
"framerate", GST_TYPE_FRACTION, fps, 1, nullptr);

gst_app_src_set_caps(GST_APP_SRC(appsrc), video_caps);

gst_app_src_set_max_bytes((GstAppSrc *)appsrc, 1 * w * h * 3);

gst_element_set_state(gpipeline, GST_STATE_PLAYING);

然后我为每一帧做:

    GstBuffer *buffer = gst_buffer_new_and_alloc(w * h * 3); 
gst_buffer_fill(buffer, 0, my_frame, w * h * 3);

if (gst_app_src_push_buffer(GST_APP_SRC(appsrc), buffer) != GST_FLOW_OK)
log(LL_WARNING, "Problem queing frame");

完整来源:complete source

最佳答案

我认为您还需要直接设置一些 appsrc 属性,而不仅仅是大写。例如。 blockdo-timestamp 不是上限,不会有任何影响。参见 https://github.com/floe/surface-streams/blob/master/common.cpp#L189-L207供引用:

  /* setup */
g_object_set (G_OBJECT (appsrc), "caps",
gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, type,
"width", G_TYPE_INT, tw,
"height", G_TYPE_INT, th,
"framerate", GST_TYPE_FRACTION, 0, 1,
NULL), NULL);
gst_bin_add_many (GST_BIN (gpipeline), appsrc, videosink, NULL);
gst_element_link_many (appsrc, videosink, NULL);

/* setup appsrc */
g_object_set (G_OBJECT (appsrc),
"stream-type", 0, // GST_APP_STREAM_TYPE_STREAM
"format", GST_FORMAT_TIME,
"is-live", TRUE,
"block", TRUE,
"do-timestamp", TRUE,
NULL);

关于gstreamer - 从 C++ 向 gstreamer 提供视频;如何让时间工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61769447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com