如何在qwidget中使用GstElement和udpsrc进行gstreamer流式传输

问题描述 投票:0回答:1

我想在qwidget中使用udpsrc嵌入IP摄像头流。以下管道工程:

gst-launch-1.0 udpsrc port = 20000! application / x-rtp,encoding-name = JPEG,payload = 26,width = 640,height = 460! rtpjpegdepay! jpegparse! jpegdec!视频转换!视频! ximagesink sync = false

当试图嵌入qwidget时,它显示了一个普通的窗口。我的代码如下:

#include <glib.h>
#include <gst/gst.h>
#include <gst/video/videooverlay.h>

#include <QApplication>
#include <QTimer>
#include <QWidget>

int main(int argc, char *argv[])
{
  if (!g_thread_supported ())
    g_thread_init (NULL);

  gst_init (&argc, &argv);
  QApplication app(argc, argv);
  app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ()));

  // prepare the pipeline

  GstElement *pipeline = gst_pipeline_new ("pipeline");
  GstElement *src = gst_element_factory_make ("udpsrc", NULL);
  GstCaps *caps = gst_caps_from_string ("application/x-rtp,encoding-name=JPEG,payload=26,width=640,height=460");

  g_object_set(G_OBJECT(src),
               "port", 20000,
               "caps", caps, NULL);

  GstElement *parser = gst_element_factory_make ("rtpjpegdepay", NULL);
  GstElement *mux = gst_element_factory_make ("jpegparse", NULL);
  GstElement *parse2 = gst_element_factory_make ("jpegdec", NULL);
  GstElement *dec = gst_element_factory_make ("videoconvert", NULL);
  GstElement *conv = gst_element_factory_make ("videoscale", NULL);
  GstElement *sink = gst_element_factory_make ("ximagesink", NULL);
  g_object_set(G_OBJECT(sink), "sync", FALSE, NULL);
  gst_bin_add_many (GST_BIN (pipeline), src, parser, mux, parse2, dec, conv, sink, NULL);
  gst_element_link (src, sink);
 GstState state, pending;

    //this is the call to overlay the gstreamer's output to the Qt Widgets...
    gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (sink), xwinid);

    GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    gst_object_unref (bus);


    GstStateChangeReturn sret = gst_element_set_state (pipeline, GST_STATE_PLAYING); //Playback can be initiated by setting the element to PLAYING state using gst_element_set_state()

    qDebug()<<"@@@@-1"<<sret;

    if (sret == GST_STATE_CHANGE_FAILURE) {
        gst_element_set_state (pipeline, GST_STATE_NULL);
        gst_object_unref (pipeline);
        // Exit application
        QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
    }

    gst_element_get_state (pipeline,
                           &state,
                           &pending,
                           10);

    qDebug()<<state<<pending;


    window->show();
    app.exec();

    g_main_loop_run (loop);
  return 0;
}
gstreamer
1个回答
0
投票

我通过使用gst_parse_launch()创建管道来解决它

GstElement *pipeline_2= gst_parse_launch("udpsrc port=20000 ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegparse ! jpegdec ! videoconvert ! videoscale ! ximagesink  name=mySink", NULL);

GstElement *sink = gst_bin_get_by_name((GstBin*)pipeline_2,"mySink");

QWidget *window = new QWidget();
window->setWindowTitle("udpsrc video stream");
window->resize(700, 700);

WId xwinid = window->winId();
gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (sink), (guintptr)xwinid);

window->show();
GstStateChangeReturn sret = gst_element_set_state (pipeline_2, GST_STATE_PLAYING);

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.