“qimage out of memory returning null image” after working for 60 QImages
-
I read a lot of posts on this topic but no post seems to help me. I am running a 32Bit Qt Application.
I wonder why I receive this error at some point:
qimage out of memory returning null image
I want to read videoframes from a mp4 File and convert them into a QImage. After that I want to convert the QImage to a QPixmap to display it on a QGraphicsView (setPixmap).
Thats the relevant code:
Function I use to convert a cv::Mat into a QPixmap:
QPixmap QtMainApp::MatToQPixmap(cv::Mat& cvMat) { QImage qimg((cvMat).data, (cvMat).cols, (cvMat).rows, (cvMat).step, QImage::Format_RGB888); return QPixmap::fromImage(qimg.rgbSwapped()); }
Where I call the function and read the videoframes from the mp4 file:
std::vector <QPixmap> vecQVideobilder{}; cv::VideoCapture videofile; videofile.open("video.mp4"); while(true) { bool bErfolg = videofile.read(MatTemp); if (!bErfolg) break; vecQVideobilder.push_back(MatToQPixmap(MatTemp)); }
The weird thing is, that it works fine for a random number of frames. I can display these frames without a problem.
But at some point (after 60 to 100 frames (it differs)) I receive the error message and I get blank images only.
I have read that It could be that the size/solution of the frame is to big for a 32Bit application QImage. But then I wonder why it is working for the first 60 or 100 frames.
Is there something I can do? Thanks in advance.
Kind regards Tim
-
@tim5 Did you observe memory consumption of your app? Maybe it gets out of memory?
-
I looked in the task-manager. I only used 50%.
Is there a way to see exactly the memory reserved for my qt app? Or is the qt app able to access all of the available memory? -
@tim5 The task manager can show how much memory an app is consuming (on the first tab). If I understood you correctly your app is 32bit? Such an app can only use up to 3GB if I'm not mistaken on Windows (or 2GB).
-
Hi,
You should check your video file, but as I wild guess, it's likely a FullHD video which is 1920 * 1024. Since you are creating a RGB QImage out of it, it's already weighing about 6MB per image. QPixmap is meant to be optimised for rendering and thus the backing memory used might even be larger for, for example, alpha channel handling. Depending on what else you do with your application and these images you can pretty quickly hit memory limits if your application is 32bit.
3/5