Qml QtMultimedia Video + Qml ShaderEffect incompatibility

Question:

I have a problem with applying a shaderEffect on qml video. When I apply ShaderEffect to the rectangle containing a video, I observe stuttering stuttering effect on Video representation in ShaderEffect. Moreover, my program shuts down some time afterwards. Are there ways to apply shader effect to QtMultimedia Video without causing stuttering? Or maybe there is another video class I should use for that purpose? Would be nice to have a solution for a rectangle containing several videos.

I looked through stackoverflow and documentation and found no answer up to now.

Upd: problem was caused not by combination of ShaderEffect and Video, but by other bugs in my project.

Asked By: Oleg Shindelov

||

Answers:

Just use yet another ShaderEffect on you ShaderEffect. That is QT.

Answered By: Roman Cherkasov

I can’t see any stuttering when using the following code. Even though I’m not using python it shouldn’t make any difference. If you want to get better answers you need to provide code in order to understand what you are doing.

import QtQuick
import QtMultimedia

Window {
    id: root
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello Shader")

    Item {
        anchors.fill: parent
        layer.enabled: true
        layer.effect: ShaderEffect {
           fragmentShader: "gray.frag.qsb"
        }

        Grid {
            rows: 2; columns: 2

            Repeater {
                id: repeater
                model: ["qrc:/video0.mp4", "qrc:/video1.mp4", "qrc:/video2.mp4", "qrc:/video3.mp4"]

                Video {
                    id: video
                    width: 320; height: 240
                    source: modelData
                    loops: MediaPlayer.Infinite
                }
            }
        }
    }

    Component.onCompleted: {
        for (let i = 0; i < repeater.count; ++i)
            repeater.itemAt(i).play()
    }
}

gray.frag

#version 440
layout(location = 0) in vec2 qt_TexCoord0;
layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;
};
layout(binding = 1) uniform sampler2D source;
void main() {
    vec4 p = texture(source, qt_TexCoord0);
    float g = dot(p.xyz, vec3(0.344, 0.5, 0.156));
    fragColor = vec4(g, g, g, p.a) * qt_Opacity;
}

As reference without the ShaderEffect applied.

without shader efffect

With ShaderEffect applied. The "stuttering" in the gif originates from me being to lazy creating a perfected looped video. So it is just starting from the beginning again hence the quick stutter.

with shader effect

Answered By: iam_peter
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.