Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trying to play video/stream Fixing Error in QGraphicsVideoItem [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Trying to play video/stream Fixing Error in QGraphicsVideoItem [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
17 Posts 2 Posters 9.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ion_knight
    wrote on last edited by
    #5

    Yea don't really care about the rtsp section until i can get a normal video playing and get the code compiling. So using the default atm

    QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),QDir::homePath());

    So should line 10 be

    QMediaPlayer *player = new QMediaPlayer;?

    As already tried that to no luck , (ha but just tried that again found a typing error gotta love it).

    So after fixing that this is now my current main.

    @#include "videoplayer.h"

    #include <QApplication>
    #include <QGraphicsView>

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    //VideoPlayer player;
    //QGraphicsView graphicsView;
    QMediaPlayer *player = new QMediaPlayer;

    QGraphicsVideoItem *item;
    QGraphicsView *graphicsView;
    player->setVideoOutput(item);
    graphicsView->scene()->addItem(item);
    graphicsView->show();
    
    player->setMedia(QUrl("http://example.com/myclip4.ogv"));
    player->play();
    
    player->show();
    
    return app.exec();
    

    }@

    but gettings these errors.

    C:\Qt\Qt5.1.0\5.1.0\msvc2010_opengl\examples\multimediawidgets\videographicsitem\main.cpp:56: error: C2664: 'QGraphicsScene::addItem' : cannot convert parameter 1 from 'QGraphicsVideoItem *' to 'QGraphicsItem *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    C:\Qt\Qt5.1.0\5.1.0\msvc2010_opengl\examples\multimediawidgets\videographicsitem\main.cpp:62: error: C2039: 'show' : is not a member of 'QMediaPlayer'

    Think i understand how to fix the second error by changing player to graphicsView

    e.g.

    graphicsView->show();

    instead of

    player->show();

    am i correct in thinking that ?

    But with the first error not really sure how to proceed, as no idea how you would typecast
    'QGraphicsVideoItem *' to 'QGraphicsItem *'

    is it something like

    addItem(QGraphicsVideoItem(*item);?

    If anyone has a link of how to do this type of typecasting that would be great.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ion_knight
      wrote on last edited by
      #6

      Ok broke down my player and think I have the most basic QMediaPlayer possible. The audio of this file plays from the console but the video doesn't the file type is .mov (h.264). Is there something that I am missing ?

      main.cpp
      @#include <QCoreApplication>
      #include <QMediaPlayer>
      #include <QFileInfo>

      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);
      QMediaPlayer media;
      const QString file = "C:/Users/nick/Downloads/big_buck_bunny_1080p_h264.mov";
      QUrl url(QFileInfo(file).absoluteFilePath());
      media.setMedia(url);
      media.play();
      return a.exec();
      }@

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #7

        You're creating a QCoreApplication, which means no GUI. Create QApplication and you should be good.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • I Offline
          I Offline
          ion_knight
          wrote on last edited by
          #8

          Well i think I am getting there (but changing it to a GUI application doesn't seemed to of changed anything) but I'm presuming by pushing the file into a surface now it should play ? (windows error below related to not having a surface set up for the media file ?).

          However the linux version just looks like i need to have the correct URI path (or do i need the URI and to push it to a surface ?). How should i be defining a path in linux to a file like "file://home/ion/Downloads/big_buck_bunny.mov"? Cause at the moment all i get is the errors listed below.

          Cheers for help so far.

          Windows Error:

          • no videoWindowControl or videoRendererControl, unable to add output node for video data

          Linux Errors:

          • GStreamer; Unable to pause - "/home/ion/Qt_practice/build-test-Desktop_Qt_5_1_0_GCC_64bit-Debug/big_buck_bunny_480p_h264.mov"

          • GStreamer; Unable to play - "/home/ion/Qt_practice/build-test-Desktop_Qt_5_1_0_GCC_64bit-Debug/big_buck_bunny_480p_h264.mov"

          • Error: "Invalid URI "/home/ion/Qt_practice/build-test-Desktop_Qt_5_1_0_GCC_64bit-Debug/big_buck_bunny_480p_h264.mov"."

          @#include "mainwindow.h"
          #include <QApplication>
          #include <QMediaPlayer>
          #include <QFileInfo>
          #include <QDebug>

          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv);
          MainWindow w;
          QMediaPlayer media;
          const QString file = "big_buck_bunny_480p_h264.mov";
          QUrl url(QFileInfo(file).absoluteFilePath());
          qDebug() << url << endl;
          media.setMedia(url);
          media.play();
          w.show();

          return a.exec&#40;&#41;;
          

          }
          @

          Ha well i think I am getting closer hopefully this should be the last post :P.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #9

            Do you have the same error using

            @QUrl url = QUrl::fromLocalFile(QFileInfo(file).absoluteFilePath());@

            ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • I Offline
              I Offline
              ion_knight
              wrote on last edited by
              #10

              Lol well that sorted that linux problem feel a bit foolish now (note to self don't watch a video when it's in a foreign language just asking for trouble) . Now both the linux and the Windows version are doing the exact same only difference is the error output.

              Both playing audio but no video. Do i need a Abstract Video surface or ?
              Linux:

              OpenGL Warning: XGetVisualInfo returned 0 visuals for 0x1b800a0

              OpenGL Warning: Retry with 0x8002 returned 0 visuals

              OpenGL Warning: XGetVisualInfo returned 0 visuals for 0x1b800a0

              OpenGL Warning: Retry with 0x8002 returned 0 visuals

              OpenGL Warning: glXGetFBConfigAttrib for 0x1b800a0, failed to get XVisualInfo

              over and over

              Windows:

              no videoWindowControl or videoRendererControl, unable to add output node for video data

              but yea still get the same error on the windows side. Also just so your aware running the linux machine in a VM.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #11

                A QVideoWidget should do it

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ion_knight
                  wrote on last edited by
                  #12

                  Ha yea What i ended up using in the end below is the updated code using QGraphicsView or QVideoWidget. Ha now all i need to do is figure out how to apply this to an RTSP stream but thats for another day :D. Cheers SGaist been very helpful.

                  @#include "mainwindow.h"
                  #include <QApplication>
                  #include <QMediaPlayer>
                  #include <QFileInfo>
                  #include <QDebug>
                  #include <QVideoWidget>
                  #include <QGraphicsView>
                  #include <QGraphicsVideoItem>

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

                  QMediaPlayer *player = new QMediaPlayer;
                   player->setMedia(QUrl::fromLocalFile&#40;"C:/Users/nick/Downloads/big_buck_bunny_1080p_h264.mov"&#41;&#41;;
                   QVideoWidget *videoWidget = new QVideoWidget;
                   w.setCentralWidget(videoWidget&#41;; // if w is a QMainWindow
                   player->setVideoOutput(videoWidget);
                   player->play();
                  

                  /*
                  QGraphicsView *graphicsView = new QGraphicsView;
                  w.setCentralWidget(graphicsView); // w = QMainWindow
                  QGraphicsScene *scene = new QGraphicsScene;
                  QMediaPlayer *player = new QMediaPlayer;
                  QGraphicsVideoItem *item = new QGraphicsVideoItem;

                  graphicsView->setScene(scene);
                  player->setVideoOutput(item);
                  
                  graphicsView->scene()->addItem(item);
                  //player->setMedia(QUrl::fromLocalFile&#40;"C:/Users/nick/Downloads/big_buck_bunny_1080p_h264.mov"&#41;&#41;;
                  player->setMedia(QUrl("rtsp://localhost:8554/stream"&#41;);
                  player->play();*/
                  
                  w.show();
                  
                  return a.exec(&#41;;
                  

                  }@

                  Btw when should I be using either? because currently just tempted to do all video output using videowidget as it looks the simpliest, is there any situation when i should use Graphics View or QAbstractVideoSurface over VideoWidget?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    For your tests, you should keep using the QVideoWidget. Once you have everything working, you can start playing with QGraphicsView and friends

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      ion_knight
                      wrote on last edited by
                      #14

                      Doesn't really answer my question but ah well setting it to solved.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #15

                        Did you meant: In which case should I use QVideoWidget and in which one QGraphicsView ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • I Offline
                          I Offline
                          ion_knight
                          wrote on last edited by
                          #16

                          Yea can't seemed to find a good example of their usage. Also would you know why QVideoWidget doesn't work on linux with that code but graphicsview does?

                          @#include "mainwindow.h"
                          #include <QApplication>
                          #include <QMediaPlayer>
                          #include <QFileInfo>
                          #include <QDebug>
                          #include <QVideoWidget>
                          #include <QGraphicsView>
                          #include <QGraphicsVideoItem>

                          int main(int argc, char argv[])
                          {
                          QApplication a(argc, argv);
                          MainWindow w;
                          /
                          QMediaPlayer *player = new QMediaPlayer;
                          const QString file = "big_buck_bunny_480p_h264.mov";
                          QUrl url = QUrl::fromLocalFile(QFileInfo(file).absoluteFilePath());
                          player->setMedia(url);
                          QVideoWidget videoWidget = new QVideoWidget;
                          w.setCentralWidget(videoWidget); // if w is a QMainWindow
                          player->setVideoOutput(videoWidget);
                          player->play();
                          /

                           QGraphicsView *graphicsView = new QGraphicsView;
                           w.setCentralWidget(graphicsView); // w = QMainWindow
                           QGraphicsScene *scene       = new QGraphicsScene;
                           QMediaPlayer *player        = new QMediaPlayer;
                           QGraphicsVideoItem *item    = new QGraphicsVideoItem;
                          
                           graphicsView->setScene(scene);
                           player->setVideoOutput(item);
                           const QString file = "big_buck_bunny_480p_h264.mov";
                           QUrl url = QUrl::fromLocalFile&#40;QFileInfo(file&#41;.absoluteFilePath(&#41;&#41;;
                           graphicsView->scene(&#41;->addItem(item);
                           player->setMedia(url);
                           //player->setMedia(QUrl("rtsp://localhost:8554/stream"));
                           player->play();
                                qDebug() << url << endl;
                          w.show();
                          return a.exec&#40;&#41;;
                          

                          }
                          @

                          The weird thing is linux says that it "Failed to start video surface" yet the video still plays bit random (but crashes after a while sometimes). (mind you probably a good idea to just create a new post to answer this question).

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #17

                            The only good answer is: it really depends on the application you are writing (I know might not sound helpful) If you are not doing anything special that would require a QGraphicsView then go for the widget.

                            As for your last question, you could directly try to see the "bug report system":http://bugreports.qt-project.org/issues and check whether it's a known issue

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved