Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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.
    4dec2169-6153-4769-a477-1d557f6697df-image.png

    It should have been like this instead (played in VLC):
    682d4dd8-a4b0-48f5-a93f-0f16fcc8eb78-image.png

    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.

    0da6cc7d-2143-4d30-9f2a-ad22a83d8a59-image.png

    1d7128c7-811f-43d4-8002-89ebfa351422-image.png

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

    747fd1c2-8bee-471b-969b-af4dc3b9777c-image.png

    78c27501-6b76-4ad3-b8b8-7ab4d507ab27-image.png


  • Lifetime Qt Champion

    What does your custom scene do ?



  • @SGaist Just drag and drop support for the QGraphicsVideoItems

    protected:
    
    	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
    {
    	Q_OBJECT
    
    public:
    	QtGuiApplication1(QWidget *parent = Q_NULLPTR);
    
    private:
    	Ui::QtGuiApplication1Class ui;
    };
    
    
    #include "QtGuiApplication1.h"
    
    QtGuiApplication1::QtGuiApplication1(QWidget *parent): QMainWindow(parent)
    {
    	ui.setupUi(this);
    	
    	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();
    
    	layout->addWidget(view);
    	ui.widget->setLayout(layout);
    	video->setFlags(QGraphicsVideoItem::ItemIsMovable | QGraphicsVideoItem::ItemIsFocusable | QGraphicsVideoItem::ItemIsSelectable);
    	video->setPos(100, 100);
            view->setScene(scene);
    	player->setMedia(path);
    	player->setVideoOutput(video);
    	scene->addItem(video);
    	player->play();
    	view->show();
    }
    
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>QtGuiApplication1Class</class>
     <widget class="QMainWindow" name="QtGuiApplication1Class">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>844</width>
        <height>639</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>QtGuiApplication1</string>
      </property>
      <widget class="QWidget" name="centralWidget">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
         <horstretch>0</horstretch>
         <verstretch>0</verstretch>
        </sizepolicy>
       </property>
       <property name="minimumSize">
        <size>
         <width>0</width>
         <height>0</height>
        </size>
       </property>
       <property name="autoFillBackground">
        <bool>true</bool>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
         <widget class="QWidget" name="widget" native="true">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
            <horstretch>0</horstretch>
            <verstretch>0</verstretch>
           </sizepolicy>
          </property>
          <property name="minimumSize">
           <size>
            <width>0</width>
            <height>400</height>
           </size>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
     </widget>
     <layoutdefault spacing="6" margin="11"/>
     <resources>
      <include location="QtGuiApplication1.qrc"/>
     </resources>
     <connections/>
    </ui>
    

Log in to reply