Qt流IP摄像机视频 [英] Qt Stream IP Camera Video

查看:375
本文介绍了Qt流IP摄像机视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Qt多媒体(Qt 5)从IP摄像机流式传输视频. 在此处可以找到类似的问题:使用Qt播放实时视频流但我尽量避免使用其他库,例如LibVLC. 我设法显示本地存储文件中的视频,但不显示IP摄像机中的流.

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.

这是我的代码:

#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;
}

如果取消注释包含QUrl :: fromLocalFile的行,则可以显示本地文件.如果我在VLC中打开指向 http://96.10.1.168/mjpg/video.mjpg

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.

为什么我不能流式传输来自IP摄像机的视频? 任何意见或调试建议将不胜感激.

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

推荐答案

您将需要使用QNetworkRequest构造函数来访问HTTP资源.

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

有关此规范,请参见QMediaContent构造函数的文档:

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.

此构造函数可用于通过网络引用媒体内容 协议,例如HTTP.这可能包括其他信息 获取资源所需的资源,例如Cookies或HTTP标头.

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

这篇关于Qt流IP摄像机视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆