Important: Please read the Qt Code of Conduct -

Show camera footage on widget and Send the video out on udp port

  • I am new Qt & Video streaming domain. I have a an requirement to show camera footage on a widget and send the same footage over network using udp.

    I am following link

    But it seems that it is not working. I have not seen any packet on udp port and video is stopped in autovideosink. May be I have missed something. Please suggest. Here is the code:

    gst_init (NULL,NULL);
    pipeline = gst_pipeline_new ("pipeline");
    g_assert( pipeline);
    testSrc = gst_element_factory_make("v4l2src", "camera");
    udp = gst_element_factory_make ("udpsink", "udp");
    g_object_set(udp , "host", "", NULL );
    g_object_set(udp , "port", 5000 , NULL );
    g_object_set(testSrc, "device", "/dev/video0", NULL);
    videoOut = gst_element_factory_make("autovideosink", "video out");
    gst_bin_add_many(GST_BIN( pipeline), testSrc, videoOut, udp, NULL);
    gst_element_link_many( testSrc, videoOut, udp, NULL);
    GstStateChangeReturn sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
        gst_element_set_state (pipeline, GST_STATE_NULL);
        gst_object_unref (pipeline);

    Also why can't it be done by


  • Lifetime Qt Champion


    If you'd like to mix GStreamer and Qt I'd recommend taking a look at the QtGstreamer project.

    As for your other question, because you are are trying to use classes rather that instances.

  • @SGaist I am using instances like:

    QCamera *camera = new QCamera(QCameraInfo::availableCameras()[0]);
    QCameraViewfinder *viewfinder = new QCameraViewfinder;
    QVideoProbe* videoProbe = new QVideoProbe(this);
    if (videoProbe->setSource(camera))
        qDebug()<<"setSource success";
        // Probing succeeded, videoProbe->isValid() should be true.
        connect(videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)),
                this, SLOT(sendDataToUdp(QVideoFrame)));

    But it is not working.

  • Lifetime Qt Champion

    What exactly is "not working" ? You have to give details, "not working" doesn't explain anything useful.

  • @SGaist, I am able to see video data on viewfinder but videoProbe->setSource(camera) is returning false, hence Slot sendDataToUdp is never getting called.

  • Lifetime Qt Champion

    You can see the status of the different backends in the wiki.

    But again, since you already have something working with GStreamer, try the Qt GStreamer module. It provides everything you need to show on a widget and stream at the same time. You'll just have to modify your gst pipeline a bit for that.

  • @gsharma Not to go against SGaist suggestion about the Qt GStreamer module, but I've just tested the brief code below and it works, slot sendDataToUdp is called. For the sake of simplicity I'm not working with the frame as I guess it needs to be converted to some appropriate format (i.e. H264?) so I'm just sending a brief message (see attached ![screenshot](

    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        udpWriter = new QUdpSocket(this);
        camera = new QCamera(this);
        viewfinder = new QCameraViewfinder(this);
        videoProbe = new QVideoProbe(this);
        if (videoProbe->setSource(camera))
            qDebug() << "setSource success";
            // Probing succeeded, videoProbe->isValid() should be true.
            connect(videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)),
                    this, SLOT(sendDataToUdp(QVideoFrame)));
        delete ui;
    void MainWindow::sendDataToUdp(const QVideoFrame &videoFrame) {
        QByteArray datagram = "Broadcasting frame " + QByteArray::number(messageNo);
        udpWriter->writeDatagram(, datagram.size(), QHostAddress::Broadcast, 45454);

  • @Pablo-J.-Rogina, I have tested the code. It is not working on QT-5.6.2 but it is working on QT-5.9.1.

  • @gsharma Ok, I forgot to mention my test environment, sorry about that.
    Well, maybe it's a good reason to update your Qt version...
    Best regards.