Important: Please read the Qt Code of Conduct -

GStreamer with Qt under Linux. Video appears only after application window is moved.

  • I have Qt 4.8.4 & GStreamer 1.0.5. I am using GStreamer's Video Overlay to display video from a cam in a Qt application.
    Once I start the GStreamer pipeline, the webcam LED lights up but I can't see the video. The video appears only after I move the application window around a bit. The relevant part of the code is
    cam_window = new QWidget(this);
    caps = gst_caps_new_simple("video/x-raw",
    "width", G_TYPE_INT, 640,
    "height", G_TYPE_INT, 480,
    pipeline = gst_pipeline_new ("pipeline");
    source = gst_element_factory_make ("v4l2src", "source");
    sink = gst_element_factory_make ("xvimagesink", "sink");

    gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
    gst_element_link_filtered (source, sink, caps);

    cam_winid = cam_window->winId();
    gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY (sink), cam_winid);
    Once the video feed has started, setting the pipeline to PAUSED and PLAYING works just fine. It is only when the pipeline is first started that I face this problem.

    • I face the same problem when I set source as "videotestsrc" instead of "v4l2src".
    • Repainting (QWidget::repaint()) or Updating(QWidget::update()) the widget after starting the pipeline doesn't fix the problem.
    • Using QGraphicsView instead of QWidget doesn't solve the problem either.

    Any suggestions? What can I try doing differently?

  • Have you tried to build the same pipeline using gst-launch?
    Does it show video immediately?

    gst-lauch-1.0 -v -e v4l2src ! xvimagesink

    Also you can check what gstreamer is doing by setting environment variable GST_DEBUG before starting your app.
    Set it to 3 or more if 3 does not produce enough info.

    something like this
    GST_DBUG=3 ./your_app

  • The latest Gstreamer version is 1.2.3
    I would suggest to switch to it if you don't have any restrictions about it.

  • [quote author="andreyc" date="1394209581"]
    Does it show video immediately?
    @gst-lauch-1.0 -v -e v4l2src ! xvimagesink@
    Yes, it shows video immediately.

    [quote author="andreyc" date="1394209581"]
    Set it to 3 or more if 3 does not produce enough info.
    @GST_DEBUG=3 ./your_app@
    Nothing useful. Just INFO messages.

    Adding a bus_sync_handler like the one given in the Gtk+ example on seems to solve the problem.
    I need multiple overlays in my Qt application. I'm not sure how to modify the bus_sync_handler to work in that case.

  • If you need to display the same source in the multiple widgets then you can create multiple pipelines or use some plugin that allows to split video stream Maybe tee pluging but I'm not sure.
    Take a look on the "examples": maybe you will find something useful there.

  • Setting a bus sync handler with gst_bus_set_sync_handler (...) and setting the video overlay with gst_video_overlay_set_window_handle(...) on the prepare_video_handle message solved the problem.
    The code from the link in my previous post works nicely.

    Thanks for your inputs anderyc.

Log in to reply