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. How to use the QMediaPlayer module to connect to a rtsp stream?
Forum Updated to NodeBB v4.3 + New Features

How to use the QMediaPlayer module to connect to a rtsp stream?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 3.0k Views
  • 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.
  • Y Offline
    Y Offline
    Ylvy
    wrote on last edited by Ylvy
    #1

    I'm streaming a window using FFmpeg and I'm trying to connect the stream to a QMediaPlayer widget, like:

    #include <QMediaPlayer>
    #include <QVideoWidget>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QMediaPlayer player;
        QVideoWidget videoWidget;
        player.setVideoOutput(&videoWidget);
        videoWidget.show();
    
        QString streamUrl = "rtsp://....:8554/stream"; 
        //QString streamUrl = "rtsp://.....129:8554/stream;tcp"
    
        player.setSource(QUrl(streamUrl));
        player.play();
    
        return a.exec();
    }
    

    It's not working and I'm getting these errors on the console:

    Exception thrown at 0x00007FF909E5CB69 in MediaPlayer.exe: Microsoft C++ exception: bad_hresult at memory location 0x0000007FD0FCA490.
    Exception thrown at 0x00007FF909E5CB69 in MediaPlayer.exe: Microsoft C++ exception: bad_hresult at memory location 0x0000007FD0FCA468.
    Exception thrown at 0x00007FF909E5CB69 in MediaPlayer.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
    Exception thrown at 0x00007FF909E5CB69 in MediaPlayer.exe: Microsoft C++ exception: bad_hresult at memory location 0x0000007FD0FCA468.
    Exception thrown at 0x00007FF909E5CB69 (KernelBase.dll) in MediaPlayer.exe: WinRT originate error - 0xC00D2EF9 : 'The text associated with this error code could not be found.'.
    handleSessionEvent: serious error =  0xC00D2EF9
    Exception thrown at 0x00007FF909E5CB69 (KernelBase.dll) in MediaPlayer.exe: WinRT originate error - 0xC00D2EF9 : 'The text associated with this error code could not be found.'.
    handleSessionEvent: serious error =  0xC00D2EF9
    

    Testing the same streamUrl on vlc it does work correctly.
    Im testing on Qt 6.5, Win10

    Christian EhrlicherC 1 Reply Last reply
    0
    • Y Ylvy

      I'm streaming a window using FFmpeg and I'm trying to connect the stream to a QMediaPlayer widget, like:

      #include <QMediaPlayer>
      #include <QVideoWidget>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QMediaPlayer player;
          QVideoWidget videoWidget;
          player.setVideoOutput(&videoWidget);
          videoWidget.show();
      
          QString streamUrl = "rtsp://....:8554/stream"; 
          //QString streamUrl = "rtsp://.....129:8554/stream;tcp"
      
          player.setSource(QUrl(streamUrl));
          player.play();
      
          return a.exec();
      }
      

      It's not working and I'm getting these errors on the console:

      Exception thrown at 0x00007FF909E5CB69 in MediaPlayer.exe: Microsoft C++ exception: bad_hresult at memory location 0x0000007FD0FCA490.
      Exception thrown at 0x00007FF909E5CB69 in MediaPlayer.exe: Microsoft C++ exception: bad_hresult at memory location 0x0000007FD0FCA468.
      Exception thrown at 0x00007FF909E5CB69 in MediaPlayer.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
      Exception thrown at 0x00007FF909E5CB69 in MediaPlayer.exe: Microsoft C++ exception: bad_hresult at memory location 0x0000007FD0FCA468.
      Exception thrown at 0x00007FF909E5CB69 (KernelBase.dll) in MediaPlayer.exe: WinRT originate error - 0xC00D2EF9 : 'The text associated with this error code could not be found.'.
      handleSessionEvent: serious error =  0xC00D2EF9
      Exception thrown at 0x00007FF909E5CB69 (KernelBase.dll) in MediaPlayer.exe: WinRT originate error - 0xC00D2EF9 : 'The text associated with this error code could not be found.'.
      handleSessionEvent: serious error =  0xC00D2EF9
      

      Testing the same streamUrl on vlc it does work correctly.
      Im testing on Qt 6.5, Win10

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Ylvy See https://forum.qt.io/topic/144882/streaming-and-showing-video-using-a-qvideowidget-object-ffmpeg/5 and the link to the bug report in there

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Y 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Ylvy See https://forum.qt.io/topic/144882/streaming-and-showing-video-using-a-qvideowidget-object-ffmpeg/5 and the link to the bug report in there

        Y Offline
        Y Offline
        Ylvy
        wrote on last edited by Ylvy
        #3

        @Christian-Ehrlicher I have downloaded the 6.6.0 source, but now it is stuck for many seconds when it read the line
        player->setSource(QUrl("rtsp://....129:8554/stream"));

        and then debug this message:
        qt.multimedia.ffmpeg.mediadataholder: AVStream duration -9223372036854775808 is invalid. Taking it from the metadata

        Also, connect(player, &QMediaPlayer::errorOccurred prints:
        Error: "Invalid argument"

        class MediaPlayer : public QObject
        {
            Q_OBJECT
        public:
            MediaPlayer (QObject* parent = nullptr) : QObject(parent)
            {
                player = new QMediaPlayer;
                player->setSource(QUrl("rtsp://....129:8554/stream"));
                connect(player, &QMediaPlayer::errorOccurred, this, [this](QMediaPlayer::Error error, const QString& errorString)
                {
                    qDebug() << "Error:" << errorString;
                });
        
                videoWidget = new QVideoWidget;
                player->setVideoOutput(videoWidget);
        
                videoWidget->show();
                player->play();
            }
        
        private:
            QMediaPlayer* player;
            QVideoWidget* videoWidget;
        };
        
        Christian EhrlicherC 1 Reply Last reply
        0
        • Y Ylvy

          @Christian-Ehrlicher I have downloaded the 6.6.0 source, but now it is stuck for many seconds when it read the line
          player->setSource(QUrl("rtsp://....129:8554/stream"));

          and then debug this message:
          qt.multimedia.ffmpeg.mediadataholder: AVStream duration -9223372036854775808 is invalid. Taking it from the metadata

          Also, connect(player, &QMediaPlayer::errorOccurred prints:
          Error: "Invalid argument"

          class MediaPlayer : public QObject
          {
              Q_OBJECT
          public:
              MediaPlayer (QObject* parent = nullptr) : QObject(parent)
              {
                  player = new QMediaPlayer;
                  player->setSource(QUrl("rtsp://....129:8554/stream"));
                  connect(player, &QMediaPlayer::errorOccurred, this, [this](QMediaPlayer::Error error, const QString& errorString)
                  {
                      qDebug() << "Error:" << errorString;
                  });
          
                  videoWidget = new QVideoWidget;
                  player->setVideoOutput(videoWidget);
          
                  videoWidget->show();
                  player->play();
              }
          
          private:
              QMediaPlayer* player;
              QVideoWidget* videoWidget;
          };
          
          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The solution in the bug report was to switch back to another backend, not using some beta software...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          Y 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            The solution in the bug report was to switch back to another backend, not using some beta software...

            Y Offline
            Y Offline
            Ylvy
            wrote on last edited by
            #5

            @Christian-Ehrlicher I know, was the first thing I tried, but it still didn't work in both versions.

            Im not sure if I tested it correctly, but what i tried was calling qputenv after the QApplication line.

            qputenv("QT_MEDIA_BACKEND", "windows");
            
            JonBJ 1 Reply Last reply
            1
            • Y Ylvy

              @Christian-Ehrlicher I know, was the first thing I tried, but it still didn't work in both versions.

              Im not sure if I tested it correctly, but what i tried was calling qputenv after the QApplication line.

              qputenv("QT_MEDIA_BACKEND", "windows");
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Ylvy
              I think you will find the whole point is that you must put the qputenv() statement before the line creating the QApplication so that the application respects your desired media backend!

              1 Reply Last reply
              1

              • Login

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