在C ++中使用Qt VLC库播放RTSP视频

时间:2018-08-08 14:38:40

标签: c++ qml vlc-qt

我正在尝试将我的VlcVideoPlayer从VLCQt库连接到使用 rts协议从网址流式传输的任何视频。

当前,这是我的代码:

import QtQuick 2.0
import VLCQt 1.0
VlcVideoPlayer {
    property var first: true
    id: vidwidget
    anchors.fill: parent
    objectName: "vlcMediaPlayer"
    url: "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov" // "http://samples.mplayerhq.hu/A-codecs/AAC/ct_faac.mp4"
    volume: 100
    aspectRatio: "16:10"
    autoplay: true
}

它与 https:// 一起使用,但是当我尝试将其更改为 rtps:// 时,我的控制台仅打印出

QML debugging is enabled. Only use this in a safe environment.
VLC-Qt "1.1.0" initialised
Using libvlc version: "2.2.2 Weatherwax"
Format: chroma: I420 width: 240 height: 162 pitches: 0 lines: 0
YV12 3 0
libvlc Error: "Track identifier not found"
libvlc: Failed to change zoom
libvlc: Failed to set on top
libvlc: Failed to change source AR

什么也没发生-没有视频显示。

当我尝试使用console.log(time)显示视频的当前时间时,时间在变化,因此我猜它正在播放视频,但没有显示。

有人对此有经验吗?我在哪里做错了?

感谢您的帮助!

//编辑:

我没有首先注意到,但是我得到的是音频,而不是视频。

2 个答案:

答案 0 :(得分:0)

因此,我在this page上进行搜索后解决了该问题,发现了类似VlcQmlPlayer的函数,其功能与VlcQmlVideoPlayer几乎相同,但它是较新的并且它的源是子类VlcQmlVideoOutput中的。因此,我为QML注册了几种类型:

qmlRegisterUncreatableType<Vlc>("Vlc", 1, 1, "Vlc", QStringLiteral("Vlc cannot be instantiated directly"));
qmlRegisterUncreatableType<VlcQmlSource>("VlcSource", 1, 1, "VlcSource", QStringLiteral("VlcQmlSource cannot be instantiated directly"));
qmlRegisterUncreatableType<VlcTrackModel>("VlcTrackModel", 1, 1, "VlcTrackModel", QStringLiteral("VlcTrackModel cannot be instantiated directly"));
qmlRegisterType<VlcQmlVideoOutput>("VlcVideoOutput", 1, 1, "VlcVideoOutput");
qmlRegisterType<VlcQmlPlayer>("VlcPlayer", 1, 1, "VlcPlayer");

然后,我像这样在QML中使用它

import VlcPlayer 1.1
import Vlc 1.1
import VlcVideoOutput 1.1

VlcVideoOutput {
    source:
        VlcPlayer {
        id: vlcPlayer
        url: "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov"
    }
}

答案 1 :(得分:0)

我的代码如下图

Main.cpp

#include <QtCore/QCoreApplication>
#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickView>

#include <VLCQtCore/Common.h>
#include <VLCQtQml/QmlSource.h>
#include <VLCQtCore/TrackModel.h>
#include <VLCQtQml/Qml.h>
#include <VLCQtQml/QmlVideoObject.h>
#include <VLCQtCore/MediaPlayer.h>
#include <VLCQtQml/QmlPlayer.h>
#include <VLCQtQml/QmlVideoOutput.h>
#include <QtPlugin>

int main(int argc, char *argv[])
{
    QCoreApplication::setApplicationName("VLC-Qt QML Player");
    QCoreApplication::setAttribute(Qt::AA_X11InitThreads);

    QGuiApplication app(argc, argv);
    VlcCommon::setPluginPath(app.applicationDirPath() + "/plugins");
    qmlRegisterUncreatableType<Vlc>("Vlc", 1, 1, "Vlc", QStringLiteral("Vlc cannot be instantiated directly"));
    qmlRegisterUncreatableType<VlcQmlSource>("VlcSource", 1, 1, "VlcSource", QStringLiteral("VlcQmlSource cannot be instantiated directly"));
    qmlRegisterUncreatableType<VlcTrackModel>("VlcTrackModel", 1, 1, "VlcTrackModel", QStringLiteral("VlcTrackModel cannot be instantiated directly"));
    qmlRegisterType<VlcQmlVideoOutput>("VlcVideoOutput", 1, 1, "VlcVideoOutput");
    qmlRegisterType<VlcQmlPlayer>("VlcPlayer", 1, 1, "VlcPlayer");

Main.qml

import VlcPlayer 1.1
import Vlc 1.1
import VlcVideoOutput 1.1

VlcVideoOutput {
    source:
        VlcPlayer {
        id: vlcPlayer
        url: "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov"
    }
}