I'm creating an RTSP stream using FFmpeg:
ffmpeg -f gdigrab -framerate 30 -probesize 100M -i title="" -c:v libx264 -preset veryfast -maxrate 1000k -bufsize 1000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 128k -f rtsp -rtsp_transport udp rtsp://...129:8554/stream
and trying to connect to it using the Qt module QMediaPlayer.
It 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 print:
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;
};
Testing the exactly same streamUrl on vlc does work correctly.
I'm using Qt 6.6, and Win10. ffmpeg 6.0
How I could debug this?
On the window platform, use the ffmpeg backend, currently Qt does not support playing rtsp video streams.
If you want to support rtsp protocol, you need to compile qt & ffmpeg yourself
--enable-protocol=rtsp
qt 6.5 build config
Env.FFMPEG_DIR_MSVCref https://wiki.qt.io/Qt_6.5_Tools_and_Versions