QML optimal way to stream/update images (Qt 5)
-
First, a little background: I'm trying to display image data streamed from a medical device in real time. The approach I am currently testing is to define a QML Image element with a custom source (e.g. "image://device/0") and use a custom QQuickImageProvider::requestPixmap() to feed the Image element with fresh data from the device.
The problem is that the Image flickers whenever I update its contents, i.e. it disappears for a moment before it reappears with the fresh data.
Is there a way to enable some form of double-buffering to avoid this ugly flicker?
Alternatively, is there a more efficient way to go about implementing this? I would imagine that I might be able to use something like a Video element with a custom source that feeds it new frames as necessary. Unfortunately, I haven't been able to find anything relevant in the documentation.
I'd be grateful if someone could point me to the right direction!
-
Did you find a solution?
-
@TomTomTom The way to do this is not to use
QQuickImageProvider
andImage
Instead use
VideoOutput
with asource
set as aQObject
based class with a writablevideoSurface
property that can accept aQAbstractVideoSurface
based class and can follow the correct protocol to deliverQVideoFrames
to it.That means that Qt will call your
videoSurface
setter with aQAbstractVideoSurface
already constructed (you don't have to create it, you just do stuff on the one passed to you). You then need to callstart
on it with theQVideoSurfaceFormat
of your choice (the one of the frames you will provide to it), and then just periodically callpresent
on it with aQVideoFrame
you generated.The only technical point here is to generate the
QVideoFrame
, and maybe decipher the doc ;).