Qt(5): Render same video on 2 different surfaces using QtMultimedia

c++, qt, qt5

Solution

Well, this was fairly simple, not the way I expected though. You gotta love QtQuick2.

So I have a MediaPlayer source and a VideoOutput item in my QML code:

MediaPlayer {
    id: mp1
    source: "slide-1.wmv"
}
VideoOutput {
    id: tbltSlides
    anchors.fill: parent
    visible: true
    source: mp1
}

All I had to do was just to add a ShaderEffectSource and set tbltSlides as its source. So simple:

ShaderEffectSource {
    id: slides
    x: 600
    width:250
    height: 250
    sourceItem: tbltSlides
    visible: true
}

EDIT: Obviously, in order to have the best quality you'd want the tbltSlides item to be bigger than the ShaderEffectSource, so that the shader downsizes the original image.

Problem

I'm developing an application in Qt(5), and basically I’m trying to render the same video source onto 2 locations in my window, using QtMultimedia5. I’m doing it in QML, but if there is a solution in C++ I will be happy to implement it instead. I have no problem to show a video in a window. Problems start when I try to use the same QMediaSource but render it onto 2 windows / controls. What I see is happening is that QMediaService::requestControl is called, which returns a QVideoRendererControl object. Then QVideoRendererControl::setSurface is called to set the surface to which it renders the video. So from what I gather QMediaService has one surface to which it renders the video at any given time. How can I render to 2 surfaces or more? Are there other classes that will suit my needs better? Cheers

Original source