Important: Please read the Qt Code of Conduct -

Rendering Issue in Video with Transparency Using QGraphicsVideoItem

  • Here is the rendering issue of an .avi video with transparency being rendered in a QGraphicsVideoItem.

    It should have been like this instead (played in VLC):

    The codec I'm using is K-Lite Mega Pack and the videos are rendering fine in other software like VLC and Adobe Premiere Pro. And the program is being developed in Visual Studio (compiled in msvc2017) using QT plugin.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What do you get if you use a QVideoWidget ?

  • I do get the correct result like in VLC. But unfortunately, my project requires to use a coordinate system and functionalities to drag the video object around. I am trying out other video format with alpha channel support as well and will further update this post.

  • Lifetime Qt Champion

    I did get that. The test with QVideoWidget is to determine whether there's an issue also there or only with QGraphicsVideoItem.

  • @SGaist Just to clarify things a bit. The correct result was from the QVideoWidget.

  • I have tested out other formats like .mov and .flv but no luck there either. So what seems to be the issue?

  • Lifetime Qt Champion

    Maybe a bug in the QGraphicsVideoItem implementation.

    Are you using the QGraphicsView only to make the video movable ?

  • Yes, I am using the original QGraphicsView but with a custom QGraphicsScene. Further digging points towards blending issue. I suspect maybe something to do with glsl shader that is used for rendering, but I'm not sure.

    The artifacts in the .avi video as shown in the previous example has premultipled alpha. When I use a new .avi video with straight alpha instead the issue is improved, but not entirely gone (black side bars gone, and less artifacts).

    For the new examples:

    Slight discoloration in the waveform.



    Other notable issue includes black outlines where there shouldn't be any.



  • Lifetime Qt Champion

    What does your custom scene do ?

  • @SGaist Just drag and drop support for the QGraphicsVideoItems

    	QString mimeType();
    	void mousePressEvent(QGraphicsSceneMouseEvent* event);
    	void dragEnterEvent(QGraphicsSceneDragDropEvent* event);
    	void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);
    	void dropEvent(QGraphicsSceneDragDropEvent* event);
    	void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
    	void keyPressEvent(QKeyEvent* event);

  • Lifetime Qt Champion

    Isn't setting the QGraphicsItem::ItemIsMovable enough for that ?

  • @SGaist Sorry, I meant drag and drop from a QTreeWidget into QGraphicsScene. Hence, I need to add additional functionalities for the drag and drop event.

    On a side note, I am able to reproduce the same artifacts with a minimal reproducible example. So, I would assume the issue doesn't stem from my code. The following is the code for the minimal reproducible example. The first image in my initial post is the result.

    #pragma once
    #include "ui_QtGuiApplication1.h"
    #include <QtCore>
    #include <QDebug>
    #include <QGraphicsVideoItem>
    #include <QGraphicsView>
    #include <QGraphicsScene>
    #include <QMediaPlayer>
    #include <QUrl>
    #include <QString>
    class QtGuiApplication1 : public QMainWindow
    	QtGuiApplication1(QWidget *parent = Q_NULLPTR);
    	Ui::QtGuiApplication1Class ui;
    #include "QtGuiApplication1.h"
    QtGuiApplication1::QtGuiApplication1(QWidget *parent): QMainWindow(parent)
    	QGraphicsView* view = new QGraphicsView(ui.widget);
    	QGraphicsScene* scene = new QGraphicsScene();
    	QGraphicsVideoItem* video = new QGraphicsVideoItem();
    	QMediaPlayer* player = new QMediaPlayer();
    	QUrl path = QUrl::fromLocalFile("FILE HERE");
    	QVBoxLayout* layout = new QVBoxLayout();
    	video->setFlags(QGraphicsVideoItem::ItemIsMovable | QGraphicsVideoItem::ItemIsFocusable | QGraphicsVideoItem::ItemIsSelectable);
    	video->setPos(100, 100);
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <widget class="QMainWindow" name="QtGuiApplication1Class">
      <property name="geometry">
      <property name="windowTitle">
      <widget class="QWidget" name="centralWidget">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
       <property name="minimumSize">
       <property name="autoFillBackground">
       <layout class="QVBoxLayout" name="verticalLayout">
         <widget class="QWidget" name="widget" native="true">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
          <property name="minimumSize">
     <layoutdefault spacing="6" margin="11"/>
      <include location="QtGuiApplication1.qrc"/>

Log in to reply