Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trying to play video/stream Fixing Error in QGraphicsVideoItem [SOLVED]
Qt 6.12 LTS is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
17 Posts 2 Posters 11.7k 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.
  • ? Offline
    ? Offline
    A Former User
    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
      • ? Offline
        ? Offline
        A Former User
        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
          • ? Offline
            ? Offline
            A Former User
            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
              • ? Offline
                ? Offline
                A Former User
                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
                  • ? Offline
                    ? Offline
                    A Former User
                    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
                      • Unsolved