Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Show camera footage on widget and Send the video out on udp port
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved General and Desktop
cameravideo outudpqt 5
9 Posts 3 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gsharma
    wrote on last edited by
    #1

    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 http://www.qtcentre.org/threads/36073-Best-way-to-stream-and-record-a-webcam.

    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");
    g_assert(testSrc);
    udp = gst_element_factory_make ("udpsink", "udp");
    g_assert(udp);
    g_object_set(udp , "host", "255.255.255.255", NULL );
    g_object_set(udp , "port", 5000 , NULL );
    g_object_set(testSrc, "device", "/dev/video0", NULL);
    
    videoOut = gst_element_factory_make("autovideosink", "video out");
    g_assert(videoOut);
    
    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);
    if (sret == GST_STATE_CHANGE_FAILURE)
    {
        gst_element_set_state (pipeline, GST_STATE_NULL);
        gst_object_unref (pipeline);
    }
    

    Also why can't it be done by

    QCamera->setViewfinder(QCameraViewfinder);
    QVideoProbe->setSource(QCamera)
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        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.

        G Offline
        G Offline
        gsharma
        wrote on last edited by gsharma
        #3

        @SGaist I am using instances like:

        QCamera *camera = new QCamera(QCameraInfo::availableCameras()[0]);
        QCameraViewfinder *viewfinder = new QCameraViewfinder;
        QVideoProbe* videoProbe = new QVideoProbe(this);
        
        camera->setViewfinder(viewfinder);
        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply
          0
          • SGaistS SGaist

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

            G Offline
            G Offline
            gsharma
            wrote on last edited by gsharma
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by Pablo J. Rogina
                #7

                @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](
                Screenshot: https://imgur.com/a/Ujupf))

                MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                
                    udpWriter = new QUdpSocket(this);
                
                    camera = new QCamera(this);
                    viewfinder = new QCameraViewfinder(this);
                    camera->setViewfinder(viewfinder);
                    setCentralWidget(viewfinder);
                    viewfinder->show();
                    camera->start();
                
                    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)));
                    }
                }
                
                MainWindow::~MainWindow()
                {
                    delete ui;
                }
                
                void MainWindow::sendDataToUdp(const QVideoFrame &videoFrame) {
                    Q_UNUSED(videoFrame);
                
                    QByteArray datagram = "Broadcasting frame " + QByteArray::number(messageNo);
                    udpWriter->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, 45454);
                    ++messageNo;
                }
                

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                G 1 Reply Last reply
                0
                • Pablo J. RoginaP Pablo J. Rogina

                  @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](
                  Screenshot: https://imgur.com/a/Ujupf))

                  MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                  
                      udpWriter = new QUdpSocket(this);
                  
                      camera = new QCamera(this);
                      viewfinder = new QCameraViewfinder(this);
                      camera->setViewfinder(viewfinder);
                      setCentralWidget(viewfinder);
                      viewfinder->show();
                      camera->start();
                  
                      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)));
                      }
                  }
                  
                  MainWindow::~MainWindow()
                  {
                      delete ui;
                  }
                  
                  void MainWindow::sendDataToUdp(const QVideoFrame &videoFrame) {
                      Q_UNUSED(videoFrame);
                  
                      QByteArray datagram = "Broadcasting frame " + QByteArray::number(messageNo);
                      udpWriter->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, 45454);
                      ++messageNo;
                  }
                  
                  G Offline
                  G Offline
                  gsharma
                  wrote on last edited by
                  #8

                  @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.

                  Pablo J. RoginaP 1 Reply Last reply
                  0
                  • G gsharma

                    @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.

                    Pablo J. RoginaP Offline
                    Pablo J. RoginaP Offline
                    Pablo J. Rogina
                    wrote on last edited by
                    #9

                    @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.

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved