Reputation: 85
I need to do some quite intensive drawing processes in my appliation - I'm recording a camera and a desktop. I'm using ffmpeg
to capture and encode/decode my videos. Those processes are quite fast and they working in a separate thread, but when it comes to render - perfomance drops drastically. I'm using QLabel
to display captured frames via setPixmap()
method and I see that Qt not using any GPU power even if a matrix operation, such as scaling an image to fit the window is clearly implied. Is there any way to paint images in Qt using hardware acceleration? Or is there another ways to speed up painting process?
Upvotes: 3
Views: 3098
Reputation: 604
Software rendering is not the only possible performance killer.
I also used to use QWidget for similar kinds of jobs, and it seems to be OK.
I assume the result of FFmpeg processing is an uncompressed byte array with YUV or RGB color scheme.
QPixmap::fromImage(...)
, which implies copying.So we have one or two full copies every frame.
Try one of the QImage constructors that uses an existing memory buffer (see Qt docs). Or, ideally, you should have a once allocated QImage and use its memory buffer with FFmpeg (FFmpeg directly writes to QImage)
Sublass QWidget, reimplement paintEvent()
and paint your QImage (not QPixmap) there.
Ideally, it should be the same QImage from the previous step.
ffmpeg
{
mutex.lock();
write(image);
mutex.unlock();
}
QWidet::paintEvent
{
mutex.lock();
paint(image);
mutex.unlock();
}
You definitely can use QOpenGLWidget for GPU drawing, which, in my opinion, wouldn't help you much.
QOpenGLWidget uses buffered rendering (i.e. copying), and it will take some cycles to upload your image from the CPU side to the GPU side. Transform operations will become faster, though.
Upvotes: 5