QVideoFrame::map() only allows one call?
-
Can QVideoFrame really do
map()
andunmap()
only once?
Have a look at the following executable code#include <QApplication> #include <QMainWindow> #include <QVBoxLayout> #include <QVideoWidget> #include <QVideoFrame> #include <QVideoSink> #include <QDebug> #include <QThread> int main(int argc, char** argv) { QApplication app(argc, argv); QWidget window; QVideoWidget* videoWidget = new QVideoWidget(&window); QImage image(200, 100, QImage::Format_RGBX8888); QVideoFrame frame = QVideoFrame(image); videoWidget->videoSink()->setVideoFrame(frame); QVBoxLayout* layout = new QVBoxLayout(&window); layout->addWidget(videoWidget); window.setLayout(layout); window.show(); auto fcn = [&] { bool map = false; //first mapping map = frame.map(QVideoFrame::WriteOnly); qDebug() << "--- 1: map" << map << "isMapped" << frame.isMapped() << "isWritable" << frame.isWritable(); frame.unmap(); QThread::msleep(250); //second mapping map = frame.map(QVideoFrame::WriteOnly); qDebug() << "--- 2: map" << map << "isMapped" << frame.isMapped() << "isWritable" << frame.isWritable(); }; QThread* thread = QThread::create(fcn); thread->start(); return app.exec(); }
I create a QVideoFrame, then I want to
map()
the frame. But the call tomap()
only succeeds first time, I cannot map the frame a second time. The relevant debug output is--- 1: map true isMapped true isWritable true --- 2: map false isMapped true isWritable false
Do I really have to create a new QVideoFrame every time I want to do a
map()
andunmap()
cycle, or is there a step missing in between? I did not find anything in the documentation? -
Trying to post some more, I get "Post content was flagged as spam by Akismet.com"
Does this work? -
Well ok, I have a draft with more code, cannot post it, cannot see a problem in the draft...
Yes I am using Qt 6.8
What I am making is sort of a video player, I have a QVideoWidget and I repeatedly set new data into the frame via map() and unmap(). This already works quite nicely but only when I create a new QVideoFrame each time I want to show a new image. For now I can live with that. But after some more experimenting I feel there is something fishy around QVideoFrame... -
@csab6597
Please put in extra copies of yourqDebug()
line. Put one immediately after theunmap()
and another immediately before the secondmap()
. You should not need theQThread::msleep(250);
, but given that you have it put in both of theseqDebug()
s so we are sure what state your are in. -
Still cannot post code "Post content was flagged as spam by Akismet.com"
The code in the image gives me
--- 1.1: map true isMapped true isWritable true --- 1.2: map true isMapped false isWritable false --- 2.0: map true isMapped true isWritable false --- 2.1: map false isMapped true isWritable false --- 2:2 map false isMapped false isWritable false
Without any sleep() it does indeed work, but I mean in reality there is some delay between frames in a video, right? I feel there is a bug somewhere.