Ip camera mjpg to QT Embedded app
Hello,
I'm trying to create a QT program to display the mjpg frames of my ip camera. For this i used QHttp without succes. On the internet i found out that it was also possible with QNetworkAccessManager. Now i've managed to show single images by using QNetworkReply and put it in a QPixmap. I'm sure it als must be possible for mjpg images but i can't figure out how.
Can anyone give me some advise. I can't use Opencv because finaly the application has to be written in QT embedded. If i'm right, i have to use the virtual framebuffer to show the mjpg images of the camera.
Below you can see my code.
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_netwManager = new QNetworkAccessManager(this);
connect(m_netwManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_netwManagerFinished(QNetworkReply*)));
connect(m_netwManager,SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),this,SLOT(slot_netwManagerFinished(QNetworkReply*,QAuthenticator*)));
}
void MainWindow::on_action_Download_triggered()
{
QUrl url
(ui
->txtImageAddress
->text
());
QNetworkRequest request(url);
m_netwManager->get(request);
}
void MainWindow::slot_netwManagerFinished(QNetworkReply*,QAuthenticator* auth)
{
auth->setUser("admin");
auth->setPassword("admin");
}
void MainWindow::slot_netwManagerFinished(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError) {
reply->deleteLater();
return;
}
QString contentType
= reply
->header
( QNetworkRequest
::ContentTypeHeader ).
toString();
if (contentType == "image/jpeg")
{
QVariant redir
= reply
->attribute
(QNetworkRequest
::RedirectionTargetAttribute);
if (redir.isValid()) {
QUrl url
= redir.
toUrl();
if (url.isRelative()) {
url.setScheme(reply->url().scheme());
url.setEncodedHost(reply->url().encodedHost());
}
QNetworkRequest req(url);
m_netwManager->get(req);
reply->deleteLater();
return;
}
pixmap.loadFromData(jpegData);
ui->lblImage->setPixmap(pixmap);
reply->deleteLater();
}
else
{
//VIDEO MJPG DATA
}
}
Re: Ip camera mjpg to QT Embedded app
Use this widget:
https://github.com/jgehring/qmpwidge.../qmpwidget.cpp
install mplayer and use the rtsp option