c++ - 如何修复 "GStreamer-CRITICAL **: gst_sample_get_buffer: assertion ' GST_IS_SAMPLE(示例 )' failed"

标签 c++ linux qt ubuntu gstreamer

我想通过 gstreamer 抓取视频帧并显示在我的应用程序上(使用 Qt),但我遇到了一些问题:

当我尝试使用 GstAppSink (gst_app_sink_pull_sample) 时,它一直返回 NULL,我不明白。我可以完美地使用终端(gst-launch-1.0)流式传输视频。

下面是我的代码:

void gstreamer::openStream()
{
    pipeline = gst_parse_launch ("rtspsrc location=rtsp://192.168.10.123 ! rtph264depay ! h264parse ! queue ! avdec_h264 ! xvimagesink sync=false async=false appsink name=mysink", NULL);

    GstElement* sink = gst_bin_get_by_name(GST_BIN(pipeline), "mysink");

    GstAppSink* appsink = GST_APP_SINK(sink);

    if(!appsink)
    {
        qDebug() << "get app sink failed";
    }
    else
    {
        qDebug() << "app sink pass";
        mAppSink = appsink;

        openSample();
    }
}

void gstreamer::openSample()
{

    if(!mAppSink)
    {
        qDebug() << "appsink failed";
    }
    GstSample* gstSample = gst_app_sink_pull_sample(mAppSink);

    if(gstSample == NULL)
    {
        qDebug() << "sample failed ";
    }
    else{
        qDebug() << "sample pass";
    }

    GstBuffer* buffer = gst_sample_get_buffer(gstSample);
    if(!buffer)
    {
        qDebug() << "buffer fail";
    }

    GstMapInfo map;

    gst_buffer_map(buffer, &map, GST_MAP_READ);


    QImage image = QImage((map.data), 320, 240, QImage::Format_RGB888);
    emit sendFrame(image);
}

我试图在网上找到,但几乎没有任何关于这个问题的链接。

最佳答案

尝试将管道更改为
“rtspsrc location=rtsp://192.168.10.123!rtph264depay!h264parse!tee name=my_tee!队列!avdec_h264!xvimagesink sync=false my_tee。!队列!appsink async=false name=mysink”

关于c++ - 如何修复 "GStreamer-CRITICAL **: gst_sample_get_buffer: assertion ' GST_IS_SAMPLE(示例 )' failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55454086/

相关文章:

linux - 并行运行 shell 脚本

c++ - QML 数据文件夹

c++ - Boost::Python 中的运算符=

c++ - 为什么不应该将 auto&& 用于局部变量?

linux - 为什么 "pstack"只打印一个线程的内容?

linux - 使用 curl 复制本地文件

c++ - 没有重载运算符 ->

c++ - 在 OSX 山狮上使用带有 Qt 5 的 libzip

c++ - 使用 memcpy 将 std::vector 复制到 protobuf 的重复字段

C++管道问题