QVideoWidget vs QGraphicsVideoItem



  • Hello,

    Why does QVideoWidget renders videos more smoothly than QGraphicsView with QGraphicsVideoItem by playing the same video?

    1. Example With QVideoWidget
    #include <QApplication>
    #include <QMainWindow>
    #include <QMediaPlayer>
    #include <QVideoWidget>
    
    int main(int argc, char *argv[])
    {
      QApplication a(argc, argv);
      QMainWindow* mw = new QMainWindow;
    
      QVideoWidget* video_widget = new QVideoWidget;
      QMediaPlayer * player = new QMediaPlayer;
      player->setVideoOutput(video_widget);
      player->setMedia(QUrl::fromLocalFile("/path/to/file.mp4"));
      mw->setCentralWidget(video_widget);
      mw->show();
      player->play();
      return a.exec();
    }
    
    1. Example with QGraphicsVideoItem
    #include <QApplication>
    #include <QMainWindow>
    #include <QMediaPlayer>
    #include <QGraphicsView>
    #include <QGraphicsVideoItem>
    #include <QGraphicsScene>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QMainWindow* mw = new QMainWindow;
        QGraphicsView* view = new QGraphicsView;
        QGraphicsScene* scene = new QGraphicsScene(view);
        view->setScene(scene);
        QMediaPlayer * player = new QMediaPlayer;
        QGraphicsVideoItem *item = new QGraphicsVideoItem;
        player->setVideoOutput(item);
        player->setMedia(QUrl::fromLocalFile("/path/to/file.mp4"));
        scene->addItem(item);
        player->play();
        mw->setCentralWidget(view);
        mw->show();
        return a.exec();
    }
    

    The figures outline are pixelated. Also increasing the size of the window on QGraphicsView have a negative impact on performance. Pictures runs slower than the sound and picture movements are abrupt. These effects doesn't occur on QVideoWidget.
    Setting the view port to OpenGL with this call view->setViewport(new QGLWidget) improves the performance but it doesn't solve the problem of the quality of the video.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Basically, the architecture behind both are not the same.

    What kind of video are you trying to play ? Why would you need a QGraphicsView for that ?



  • @SGaist
    The video is a test video downloaded from youtube. For example https://www.youtube.com/watch?v=qPTfXwPf_HM converted and downloaded by http://convert2mp3.net/. Using another video formats than mp4 doesn't change anything on this fact.

    I am trying to create a template as a multimedia widget in what user can compose different items like video, picture, graphics or animating texts for rendering on a screen. I have just startet to evaluate QGraphicsView for this purpose.

    Thanks


  • Lifetime Qt Champion

    Then I'd recommend taking a look at QtQuick for that kind of stuff.



  • @SGaist
    Hi,
    I looked at the examples qmlvideo and qmlvideofx from qt 5.9 which are implemented with QtQuick 2 and they have apparently the same problem. QVideoWidget have the best rendering behavior also compared to the QtQuick option in my opinion. With QVideoWidget there is no pixelization and no erratic playback. I don't know what the problem here.


  • Lifetime Qt Champion

    What are your platform and Qt version ?



  • @SGaist
    I work with Windows 7 and 10. Qt Version is 5.9. I have also installed K-lite codec 13.3.3


  • Lifetime Qt Champion

    Which version of 5.9 ?



  • @SGaist
    I use Qt 5.9.1 MSVC 2015, 32 bit and MinGW32 bit - Open Source (LGPLv3).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.