ustulation
30th December 2012, 17:19
I am trying to design an application to play multiple video (media) files and allow user modification capability on each one (eg, scaling, rotating, inverting etc of videos). I started by studying Phonon, but after going into it for a while read that it is no longer supported (or its support is doubtful) in >= Qt5. So then i went back and now i'm looking at qtmultimedia - QMediaPlayer. I'm stuck and confused on what widgets i must use. QMediaPlayer can show its output (video) on QVideoWidget, QGraphicsVideoItem and QAbstractVideoSurface. Since I need the capabilities of rotation etc, i believe i must incorporate QGraphicsScene/View.
<1> So what should the approach be? I did this: used QVideoWidget -> added this to QGraphicsProxyWidget via its setWidget() (though setWidget() takes QWidget* and QVideoWidget is not derived from QWidget as i see in Qt Assistant -- why is this allowed btw?) -> Added this QGraphicProxyWidget to QGraphicsScene via addItem() -> added this QGraphicsScene to QGraphicsView while constructing it -> added QGraphicsView to QMainWindow via setCentralWidget(). Is this fine? When to use QGraphicsVideoItem and QAbstractVideoSurface?
<2> When adding multiple QVideoWidget in the following manner i don't see any video or the QVideoWidget itself (i've painted to distinguish it). What am i doing wrong? (there is audio output though):
QVideoWidget *pVideoWidget1 = new QVideoWidget(0);
pVideoWidget1->setPalette(QPalette(QColor(255,0,0),QColor(0,255,0 )));
QVideoWidget *pVideoWidget2 = new QVideoWidget(0);
pVideoWidget2->setPalette(QPalette(QColor(255,0,0),QColor(0,0,255 )));
m_pMediaPlayer1 = new QMediaPlayer(this);
m_pMediaPlayer2 = new QMediaPlayer(this);
m_pMediaPlayer1->setVideoOutput(pVideoWidget1);
m_pMediaPlayer2->setVideoOutput(pVideoWidget2);
m_pCustomGraphicsProxy1 = new CustomGraphicsProxy(0); //this is just a class derived from QGraphicsProxyWidget to implement drag and drop of videos
m_pCustomGraphicsProxy2 = new CustomGraphicsProxy(0);
m_pCustomGraphicsProxy1->setWidget(pVideoWidget1);
m_pCustomGraphicsProxy2->setWidget(pVideoWidget2);
QGraphicsScene *pGraphicsScene = new QGraphicsScene(this);
QGraphicsLinearLayout *pGraphicsLinearLayout = new QGraphicsLinearLayout;
CustomGraphicsProxy* button = new CustomGraphicsProxy(0);
button->setWidget(new QPushButton); //this i can see
CustomGraphicsProxy* button1 = new CustomGraphicsProxy(0);
button1->setWidget(new QPushButton); //this i can see too
pGraphicsLinearLayout->addItem(button);
pGraphicsLinearLayout->addItem(m_pCustomGraphicsProxy1); //can't see
pGraphicsLinearLayout->addItem(m_pCustomGraphicsProxy2); //can't see
pGraphicsLinearLayout->addItem(button1);
CustomGraphicsProxy *temp = new CustomGraphicsProxy(0);
temp->setLayout(pGraphicsLinearLayout);
pGraphicsScene->addItem(temp);
temp->show();
m_pGraphicsView = new QGraphicsView(pGraphicsScene, this);
setCentralWidget(m_pGraphicsView);
QObject::connect(m_pCustomGraphicsProxy1, SIGNAL(sigNewFileDragDropped()), this, SLOT(sloPlayOnWindow1()));
QObject::connect(m_pCustomGraphicsProxy2, SIGNAL(sigNewFileDragDropped()), this, SLOT(sloPlayOnWindow2()));
//just for testing - this gives only audio no video can be seen
m_pMediaPlayer1->setMedia(QUrl::fromLocalFile("d:/z.avi"));
m_pMediaPlayer1->play();
<3> Before i study this further, am i choosing the right tools in Qt to manipulate videos as i mentioned before or something else needs to be done?
<1> So what should the approach be? I did this: used QVideoWidget -> added this to QGraphicsProxyWidget via its setWidget() (though setWidget() takes QWidget* and QVideoWidget is not derived from QWidget as i see in Qt Assistant -- why is this allowed btw?) -> Added this QGraphicProxyWidget to QGraphicsScene via addItem() -> added this QGraphicsScene to QGraphicsView while constructing it -> added QGraphicsView to QMainWindow via setCentralWidget(). Is this fine? When to use QGraphicsVideoItem and QAbstractVideoSurface?
<2> When adding multiple QVideoWidget in the following manner i don't see any video or the QVideoWidget itself (i've painted to distinguish it). What am i doing wrong? (there is audio output though):
QVideoWidget *pVideoWidget1 = new QVideoWidget(0);
pVideoWidget1->setPalette(QPalette(QColor(255,0,0),QColor(0,255,0 )));
QVideoWidget *pVideoWidget2 = new QVideoWidget(0);
pVideoWidget2->setPalette(QPalette(QColor(255,0,0),QColor(0,0,255 )));
m_pMediaPlayer1 = new QMediaPlayer(this);
m_pMediaPlayer2 = new QMediaPlayer(this);
m_pMediaPlayer1->setVideoOutput(pVideoWidget1);
m_pMediaPlayer2->setVideoOutput(pVideoWidget2);
m_pCustomGraphicsProxy1 = new CustomGraphicsProxy(0); //this is just a class derived from QGraphicsProxyWidget to implement drag and drop of videos
m_pCustomGraphicsProxy2 = new CustomGraphicsProxy(0);
m_pCustomGraphicsProxy1->setWidget(pVideoWidget1);
m_pCustomGraphicsProxy2->setWidget(pVideoWidget2);
QGraphicsScene *pGraphicsScene = new QGraphicsScene(this);
QGraphicsLinearLayout *pGraphicsLinearLayout = new QGraphicsLinearLayout;
CustomGraphicsProxy* button = new CustomGraphicsProxy(0);
button->setWidget(new QPushButton); //this i can see
CustomGraphicsProxy* button1 = new CustomGraphicsProxy(0);
button1->setWidget(new QPushButton); //this i can see too
pGraphicsLinearLayout->addItem(button);
pGraphicsLinearLayout->addItem(m_pCustomGraphicsProxy1); //can't see
pGraphicsLinearLayout->addItem(m_pCustomGraphicsProxy2); //can't see
pGraphicsLinearLayout->addItem(button1);
CustomGraphicsProxy *temp = new CustomGraphicsProxy(0);
temp->setLayout(pGraphicsLinearLayout);
pGraphicsScene->addItem(temp);
temp->show();
m_pGraphicsView = new QGraphicsView(pGraphicsScene, this);
setCentralWidget(m_pGraphicsView);
QObject::connect(m_pCustomGraphicsProxy1, SIGNAL(sigNewFileDragDropped()), this, SLOT(sloPlayOnWindow1()));
QObject::connect(m_pCustomGraphicsProxy2, SIGNAL(sigNewFileDragDropped()), this, SLOT(sloPlayOnWindow2()));
//just for testing - this gives only audio no video can be seen
m_pMediaPlayer1->setMedia(QUrl::fromLocalFile("d:/z.avi"));
m_pMediaPlayer1->play();
<3> Before i study this further, am i choosing the right tools in Qt to manipulate videos as i mentioned before or something else needs to be done?