Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

VideoFrameProbed signal transfers empty frames



  • Hi guys, I've been developing this app that would capture video from camera and send it through UDP socket.

    I've got a Camera object in main.qml

            Camera {
                id: qmlCamera
                objectName: "qmlCamera"
            }
                VideoOutput {
                    id: senderVideo
                    source: qmlCamera
                    focus : visible
                }
    

    Here is the code that should refer to that Camera object and establish a connection between videoFrameProbed signal and onVideoFrameProbed slot:

    class videoSender : public QObject
    {
        Q_OBJECT
    public:
        explicit videoSender(QObject *parent = nullptr)
            : m_camera(qvariant_cast<QCamera*>(parent->property("mediaObject"))),
              m_videoProbe(new QVideoProbe)
        {
            initializeSocket();
    
            if(m_videoProbe->setSource(m_camera))
                qDebug() << "setSource success";
            connect(m_videoProbe, SIGNAL(videoFrameProbed(const QVideoFrame)),
                    this, SLOT(onVideoFrameProbed(const QVideoFrame)));
        }
    ...
    

    That's how I initialize the videoSender object:

        QObject *qmlCamera = engine.rootObjects().at(0)->findChild<QObject*>("qmlCamera");
        videoSender *vs = new videoSender(qmlCamera);
    

    It works as intended until I try to process a videoProbe in this slot:

    void videoSender::onVideoFrameProbed(const QVideoFrame &videoFrame){
    
        qDebug() << videoFrame.bits();  // returns 0x0
        qDebug() << videoFrame.mappedBytes();   // returns 0
    
        QImage img(videoFrame.bits(),
                   videoFrame.width(),
                   videoFrame.height(),
                   videoFrame.bytesPerLine(),
                   QVideoFrame::imageFormatFromPixelFormat(videoFrame.pixelFormat()));
    
        QByteArray data;
        QDataStream ds(&data, QIODevice::ReadWrite);
    
        ds.writeRawData((const char*)img.bits(), img.byteCount());
        ds.device()->seek(0);
        qDebug() << data.size();  // returns 0
    
        m_socket->writeDatagram(data, QHostAddress::LocalHost, 7755);
    }
    

    So a good thing is that videoFrameProbed signal is actually emitted, but it seems to transfer an empty frame that bits and mappedBytes attributes are set to 0. Also .isValid() method returns true and .size() returns the actual size of the camera window.
    I might be missing something here as this is my first project with multimedia. Also sorry for my bad english


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are assuming that you have an image in QVideoFrame which might not be the case.

    See QVideoFrame::handleType.


Log in to reply