Showing video from a rtsp ip camera
-
I have hit a bricked wall in trying to show a rtsp from a cctv camera. Im using qt6 and have tried both C++ and QML to no avail. Im currently trying it on windows OS . I can already confirm that in vlc my rtsp link works. I can also confirm that both programs C++ and QML has no problem playing an mp4 file that is stored locally.
Here is my C++ attempt
video = new QVideoWidget(this); video->setGeometry(80,80,this->width(),this->height()); video->show(); player = new QMediaPlayer(this); audio = new QAudioOutput(this); connect(player,&QMediaPlayer::errorChanged,this,&MainWindow::mediaPlayerDebugError); connect(player,&QMediaPlayer::mediaStatusChanged,this,&MainWindow::mediaPlayerDebugStatus); player->setVideoOutput(video); player->setSource(QUrl("rtsp://admin:admin@192.168.1.199:554/mpeg4/ch0/main/av_stream")); player->play();
C++ qDebug show me an error
Status Changed: QMediaPlayer::LoadingMedia Status Changed: QMediaPlayer::InvalidMedia Error: QMediaPlayer::ResourceError
Here is my QML attempt
Window { id:mainWidow width: 600 height: 600 visible: true title: qsTr("Hello World") MediaPlayer { id: player source: "rtsp://admin:admin@192.168.1.199:554/mpeg4/ch0/main/av_stream" videoOutput: videoOutput onErrorOccurred: { console.log(player.errorString) console.log(player.mediaStatus) } Component.onCompleted: {mainWidow.title = qsTr("started"); player.play()} } VideoOutput { id: videoOutput anchors.fill: parent anchors.horizontalCenter: parent.horizontalCenter } }
QML throws me an error of
qml: Failed to load source. qml: 7 // QMediaPlayer::InvalidMedia
Invalid media seems to be the common problem, does anyone know how to fix this? or if you have successfully played a rtsp stream can you share how you did it? If you need info concerning the ip camera just tell me ill try to look for it.
-
I have solved the C++ project and now im able to show the stream, but it really delayed around 10 seconds of delay compared to 4-5seconds of delay in VLC
The problem was i did not include QUrl
All includes in mainwindow.h
#include <QMainWindow> #include <QMediaPlayer> #include <QVideoWidget> #include <QAudioOutput> #include <QPushButton> #include <QUrl> #include <QDebug>
-