QImage to Qpixmap conversion is too slow
-
I want to display video and show its frames to the gui. I have a processor that pumps out packed RGB data, and to display them, I have a
QImage
that took in the data and convert them toQPixmap
for display. However theQImage
toQPixmap
conversion is too slow for real time play speed. It played fine when the videos are around 1080p, but with 4K video, the fps just plummeted.QImage frame_image(data, width, height, QImage::Format_ARGB32); QPixmap frame_pixmap = QPixmap::fromImage(frame_image);
What is a faster way to do this?
-
I want to display video and show its frames to the gui. I have a processor that pumps out packed RGB data, and to display them, I have a
QImage
that took in the data and convert them toQPixmap
for display. However theQImage
toQPixmap
conversion is too slow for real time play speed. It played fine when the videos are around 1080p, but with 4K video, the fps just plummeted.QImage frame_image(data, width, height, QImage::Format_ARGB32); QPixmap frame_pixmap = QPixmap::fromImage(frame_image);
What is a faster way to do this?
@lansing said in QImage to Qpixmap conversion is too slow:
What is a faster way to do this?
Use a proper backend for your task. CPU raster is definitely not made for such kind of work. Use OenGL or similar instead.
-
@lansing said in QImage to Qpixmap conversion is too slow:
What is a faster way to do this?
Use a proper backend for your task. CPU raster is definitely not made for such kind of work. Use OenGL or similar instead.
@Christian-Ehrlicher said in QImage to Qpixmap conversion is too slow:
@lansing said in QImage to Qpixmap conversion is too slow:
What is a faster way to do this?
Use a proper backend for your task. CPU raster is definitely not made for such kind of work. Use OenGL or similar instead.
Is there any example with OpenGL? Like where do I start?
-
Hi,
Can you give more information about how are these images created ? Passed around ?
Are they from a camera ?
Are you loading them from a file ?
Etc. -
Hi,
Can you give more information about how are these images created ? Passed around ?
Are they from a camera ?
Are you loading them from a file ?
Etc.They were loaded from a video file, then go into a processor where it will spit out packed RGB data frame by frame.
I found a stackoverflow answer about passing the
QImage
into aQOpenGLWidget
and then using itspaintEvent
to draw out the image, is this the way?https://stackoverflow.com/questions/20245865/render-qimage-with-opengl
-
What are you using to read your video file ?
Depending on that and the image format you could load the data directly into a texture and do the color space conversion in OpenGL rather than on the CPU side. -
What are you using to read your video file ?
Depending on that and the image format you could load the data directly into a texture and do the color space conversion in OpenGL rather than on the CPU side.@SGaist said in QImage to Qpixmap conversion is too slow:
What are you using to read your video file ?
Depending on that and the image format you could load the data directly into a texture and do the color space conversion in OpenGL rather than on the CPU side.That can be a future plan, but I want to do it one step at a time. For right now I need to know where to even start. The
Qimage
toQPixmap
conversion is cutting my playback speed in half. -
@SGaist said in QImage to Qpixmap conversion is too slow:
What are you using to read your video file ?
Depending on that and the image format you could load the data directly into a texture and do the color space conversion in OpenGL rather than on the CPU side.That can be a future plan, but I want to do it one step at a time. For right now I need to know where to even start. The
Qimage
toQPixmap
conversion is cutting my playback speed in half. -
@lansing
Hi
well try the OpenGLWidget::paintEvent code and see if its fast enough.
At least you don't have the conversion to pixmapHi This is what I have done so far:
class MyGLPainter : public QOpenGLWidget { Q_OBJECT public: MyGLPainter (QWidget *parent = nullptr); void paintEvent(QPaintEvent *) override; void drawImage(const QImage &image); private: QImage m_frameImage;
MyGLPainter::MyGLPainter (QWidget *parent): QOpenGLWidget(parent) { } void MyGLPainter::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawImage(m_frameImage.width(),m_frameImage.height(), m_frameImage); painter.end(); } void MyGLPainter::drawImage(const QImage &image) { m_frameImage = image; update(); }
But when I pass the image to
drawImage()
, the program will just crash. Am I doing this correctly? -
Hi This is what I have done so far:
class MyGLPainter : public QOpenGLWidget { Q_OBJECT public: MyGLPainter (QWidget *parent = nullptr); void paintEvent(QPaintEvent *) override; void drawImage(const QImage &image); private: QImage m_frameImage;
MyGLPainter::MyGLPainter (QWidget *parent): QOpenGLWidget(parent) { } void MyGLPainter::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawImage(m_frameImage.width(),m_frameImage.height(), m_frameImage); painter.end(); } void MyGLPainter::drawImage(const QImage &image) { m_frameImage = image; update(); }
But when I pass the image to
drawImage()
, the program will just crash. Am I doing this correctly? -
Do you update your image from a different thread? If so you should learn about threading: Threading Basics
-
Do you update your image from a different thread? If so you should learn about threading: Threading Basics
HI, is this related to the crash?
-
HI, is this related to the crash?
-
@lansing
Hi
then something is wrong with the image then.
Else why crash on copy.can you try with Image that you are 100% sure is valid ?
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
-
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
-
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
@lansing said in QImage to Qpixmap conversion is too slow:
myGLPainter
Where do you initialize this variable?