3

I am trying to stream the video from an IP camera using Qt multimedia (Qt 5). A similar question could be found here: Play a Live video Stream using Qt but I try to avoid using an other library such as LibVLC. I manage to display the video from a locally stored file but not to display the stream from the IP camera.

Here is my code:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMediaPlayer>
#include <qvideowidget.h>
#include <QVideoWidget>

#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this-> resize(1000,1000);
    QMediaPlayer *mp = new QMediaPlayer(0,0);
    QMediaContent *mc = new QMediaContent(QUrl("http://96.10.1.168/mjpg/video.mjpg"));
    //QMediaContent *mc = new QMediaContent(QUrl::fromLocalFile("/Users/userName/Desktop/marsUni.mp4"));
    mp->setMedia(*mc);
   QVideoWidget *vw = new QVideoWidget(this);
   vw->setMaximumSize(704, 576);
   vw->setMinimumSize(704, 576);

   mp->setVideoOutput(vw);
   this->setCentralWidget(vw);
   vw->show();
   mp->play();
}

MainWindow::~MainWindow()
{
    delete ui;
}

If I uncomment the line containing QUrl::fromLocalFile, I can display the local file. If I open a network connection in VLC pointing to http://96.10.1.168/mjpg/video.mjpg, I can display the camera stream. I am on Mac OS 10.9.

Why cant I stream the video from the IP camera? Any comments or debugging suggestion would be appreciated.

Castim
  • 115
  • 1
  • 2
  • 9

1 Answers1

3

You'll need to use the QNetworkRequest constructor to access an HTTP resource.

The specification for this is in the documentation for the QMediaContent constructor:

QMediaContent::QMediaContent(const QNetworkRequest & request)

Constructs a media content with request providing a reference to the content.

This constructor can be used to reference media content via network protocols such as HTTP. This may include additional information required to obtain the resource, such as Cookies or HTTP headers.

http://doc.qt.io/qt-5/qmediacontent.html#QMediaContent-3

Andrew Dolby
  • 799
  • 1
  • 13
  • 25