How to use the QMediaPlayer module to connect to a rtsp stream?
-
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
onvlc
it does work correctly.
Im testing on Qt 6.5, Win10 -
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
onvlc
it does work correctly.
Im testing on Qt 6.5, Win10@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
-
@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
@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-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; };
The solution in the bug report was to switch back to another backend, not using some beta software...
-
The solution in the bug report was to switch back to another backend, not using some beta software...
@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");
-
@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");