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

Play RTSP video with Qt VLC libary in C++

我正在尝试将我的 VlcVideoPlayer 从 VLCQt 库连接到使用 rts 协议 .

从 url 流式传输的任何视频

目前,这是我的代码:

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) 显示视频的当前时间时,时间在变化,所以我猜它正在播放视频,但它没有显示。

有人有这方面的经验吗?我哪里做错了?

感谢您的帮助!

//编辑:

我一开始没注意到,但我得到的是音频,而不是视频。

所以,我在 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"
    }
}

我的代码如下图

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"
    }
}

作为参考,您可以将所有这些 qmlRegister() 函数替换为:

#include <VLCQtCore/Common.h>
#include <VLCQtQml/Qml.h>

int main( )
{
...
    VlcCommon::setPluginPath( app.applicationDirPath( ) + "/plugins" );
    VlcQml::registerTypes( );
...
}

import VLCQt 1.1

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