E
E
Egorithm2020-07-05 16:31:36
Qt
Egorithm, 2020-07-05 16:31:36

Qt. Why can't convert QVideoFrame to QImage?

In general, there is a method QVideoFrame::image(), but it appeared only in Qt 5.15 (and I have 5.14.2). But there is an old way with the transfer: a pointer to a byte sequence, width, height, bytes per line and format. This is how I process it:

void MainWindow::processFrame(const QVideoFrame &frame)
{
    QImage image{ frame.bits(), frame.width(), frame.height(), frame.bytesPerLine(),
                  QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat()) };

    std::clog << frame.width() << " " << frame.height() << "\n"
              << image.width() << " " << image.height() << "\n";

    std::clog << frame.pixelFormat() << "\n"
              << QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat()) <<"\n";
}

Such a conclusion:
1280 720
0 0
1
5

The format seems to match:
QVideoFrame::Format_ARGB32 == 1
QImage::Format_ARGB32 == 5

I don't understand what could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egorithm, 2020-07-05
@EgoRusMarch

I found out that QVideoFramethere is a method isMapped()that shows whether the frame is located in RAM (or in virtual memory, i.e. whether it is in addressable memory and whether it can be accessed). It turned out that no.
Because the signal QVideoProbe::videoFrameProbed()passes a reference to a constant QVideoFrame, and the function is QVideoFrame::map()not constant, then you need to copy the frame:

void MainWindow::proccessFrame(const QVideoFrame &frame)
{
    QVideoFrame replica = frame;
    replica.map(QAbstractVideoBuffer::ReadOnly);

    std::clog << std::boolalpha << frame.isMapped()   << "\n";
    std::clog << std::boolalpha << replica.isMapped() << "\n";

    QImage image{ replica.bits(), replica.width(),
                  replica.height(), replica.bytesPerLine(),
                  QVideoFrame::imageFormatFromPixelFormat(replica.pixelFormat()) };

    std::clog << replica.width() << " " << replica.height() << "\n";
    std::clog << frame.width()   << " " << frame.height()   << "\n";
    std::clog << image.width()   << " " << image.height()   << "\n";

    std::clog << frame.pixelFormat() << "\n";
    std::clog << QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat()) << "\n";
}

A
Alexander Kamolov, 2014-11-09
@levik200

Look here for my answers:
What languages ​​do you need to know in the field of information security?
What do you need to know to become a hacker?
Information Security Books and Resources
How do I start learning about information security?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question