高性能QImage输出显示 [英] High performance QImage output to display
问题描述
我想让视频输出(帧序列)到任何qt可见的小部件。开始我认为QLabel将足够了这一点...但我错了。
I'm trying to make video output (sequence of frames) to any qt visible widget. At beginning i thought that QLabel will be enough for this point... but i was wrong. Converting to pixmap is too overloading for processor at large images: 1080p for example.
任何其他解决方案? (不是QLabel?)
Any other solution? (not QLabel?)
一个框架的代码示例:
QImage m_outputFrameImage(width, height, QImage::Format_RGB888);
memcpy(m_outputFrameImage.bits(), m_frameRGB->data[0], height * width * 3);
QPixmap pixmap = QPixmap::fromImage(m_outputFrameImage); // BAD, slow and high load
/* Bad too (Same code?)
QPainter painter;
painter.begin(&pixmap);
painter.drawImage(0, 0, m_outputFrameImage);
painter.end();
*/
labelVideo->setPixmap(pixmap);
推荐答案
code> QGLWidget ,让视频卡处理它。这是Qt MultimediaKit,Phonon和其他人做的。
Yes, render the frames to a QGLWidget
and let the video card handle it. That's how Qt MultimediaKit, Phonon and others do it.
前一段时间,我共享了一些演示如何完成此任务的代码:通过OpenGL实现图像缩放(KeepAspectRatioByExpanding)
Some time ago I shared some code that demonstrated how to accomplish this task: Image scaling (KeepAspectRatioByExpanding) through OpenGL
这篇关于高性能QImage输出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!