Search code examples
c++qtqmlgstreamerqt5.5

How to include a gstreamer sink in a QML VideoItem?


I'm trying to integrate a gsrtreamer video in a QT app using QML.

I've begun with the example qmlplayer2 which uses a distant video :

player->setUri(QLatin1Literal("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"));

I've modified this example to use a pipeline to get an udpsrc :

    m_pipeline = QGst::Pipeline::create();
    QGst::ElementPtr udp = QGst::ElementFactory::make(QLatin1Literal("udpsrc"));
    udp->setProperty("address", "192.168.1.1");
    udp->setProperty("port", 3333);
    QGst::ElementPtr decodage = QGst::ElementFactory::make("jpegdec");
    QGst::ElementPtr videosink = QGst::ElementFactory::make("autovideosink");

Which is equivaltent to :

gst-launch-1.0 udpsrc address=192.168.1.1 port=3333 ! jpegdec ! autovideosink

This works, I get my video streamed and my play/pause/stop buttons working.

But The video is in an different window Two separate windows

Whereas my QML is specifying that VideoItem is in the main window :

Rectangle {
    id: window
    width: 600
    height: 300
    Column {
        width: 600
        height: 544
        y : 10;
        VideoItem {
            id: video
            y : 10;
            width: window.width
            height: 260
            surface: videoSurface1 //bound on the context from main()
        }
        // Other buttons

Every topic I found is either too old (gstreamer is native in Qt since 5.5 this year) or does not have answers

Is there a mistake in my work ?

Is there an other way to do what I want?

Thanks.


Solution

  • The problem here is autovideosink doesn't implement "GstVideoOverlay". In your pipeline your should use as a sink element one of this elements "xvimagesink,ximagesink" or use "playbin" directly, this elements implements "GstVideoOverlay" interface .

    Here an example using "playbin". Note this example is using pure Gstreamer without QT wrapers.

    GstElement *pipeline = gst_element_factory_make("playbin", "playbin");
    /* Set the URI to play */
    g_object_set(pipeline, "uri", url, NULL);
    gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(pipeline), windowsID);
    

    *windowsID is the widget id where you want draw your video output. *url is your video url. For you would be "udp://192.168.1.1:3333"