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.
-
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.
-
I did get that. The test with QVideoWidget is to determine whether there's an issue also there or only with QGraphicsVideoItem.
-
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.
-
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);
-
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>