PDA

View Full Version : QGraphicsVideoItem crashes on video play



tuli
8th April 2015, 07:50
Hi!

I am trying to implement a zoom-able video playing, which is only possible by using QGraphicsVideoItem in a QGraphicssView, I have been told. This would be a basic example:




QGraphicsView * graphicsView = new QGraphicsView;
QMediaPlayer * player = new QMediaPlayer;

QGraphicsScene * scene = new QGraphicsScene;
graphicsView->setScene(scene);

QGraphicsVideoItem *item = new QGraphicsVideoItem;
player->setVideoOutput(item);
graphicsView->scene()->addItem(item);
graphicsView->show();

player->setMedia(QUrl::fromLocalFile("c:/x.mp4"));
player->play();


however, it chokes on a debug assert:


---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Error!

Program: C:\Qt5\5.4\msvc2013_64\bin\Qt5Cored.dll
Module: 5.4.1
File: global\qglobal.cpp
Line: 2868

ASSERT: "m_surface" in file player\mfvideorenderercontrol.cpp, line 2342

(Press Retry to debug the application)

---------------------------
Abort Retry Ignore
---------------------------


I looked into it, but I have no idea why the assert is fired.

Q_ASSERT(m_surface);

As far as i can tell, m_surface is non-NULL. :(



Anyways, the crash also occurs when I just create a QGraphicsVideoItem without adding it to anything.



QMediaPlayer * player = new QMediaPlayer;
QGraphicsVideoItem *item = new QGraphicsVideoItem;
player->setVideoOutput(item);

player->setMedia(QUrl::fromLocalFile("c:/x.mp4"));
player->play();


i can only guess that the crash is related to the QGraphicsVideoItem not offering a proper surface to render the video on? Where do I go wrong?


I am using Qt 5.4 + MSVC 2013 + Win7.

wysota
8th April 2015, 07:57
Do you have proper video backend for your platform installed?

tuli
8th April 2015, 08:16
Yes. I can play the video fine with a QVideoWidget.

wysota
8th April 2015, 09:43
Did you add the item to a scene? Aah, I see you did. Can you prepare a minimal compilable example reproducing the problem?

tuli
8th April 2015, 11:27
Sure!

Just adjust the path to the mp4 file.


#include <QWidget>
#include <QtCore>
#include <QtGui>
#include <QtWidgets>
#include <QtMultimedia>

#include <QGraphicsVideoItem>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QMediaPlayer * player = new QMediaPlayer;
QGraphicsVideoItem *item = new QGraphicsVideoItem;
player->setVideoOutput(item);
player->setMedia(QUrl::fromLocalFile("c:/x.mp4"));
player->play();

return a.exec();
}

wysota
8th April 2015, 11:44
Well, here you are not adding the item to a scene.

This works for me:


#include <QApplication>
#include <QMediaPlayer>
#include <QGraphicsVideoItem>
#include <QGraphicsView>
#include <QGraphicsScene>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMediaPlayer * player = new QMediaPlayer;
QGraphicsVideoItem *item = new QGraphicsVideoItem;
player->setVideoOutput(item);
player->setMedia(QUrl::fromLocalFile("/tmp/a/sintel_trailer-480p.mp4"));
QGraphicsScene scene;
scene.addItem(item);
QGraphicsView view;
view.setScene(&scene);
view.show();
player->play();
return a.exec();
}

tuli
8th April 2015, 12:12
Both your and my snippet cause the described crash.