Воспроизведение видео RTSP с помощью библиотеки Qt VLC на C++
Я пытаюсь подключить VlcVideoPlayer
из библиотеки VLCQt на любое видео, передаваемое по URL с протоколом 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)
Время менялось, поэтому я думаю, что оно воспроизводит видео, но оно не отображается.
Кто-нибудь имеет опыт работы с этим? Где я делаю ошибку?
Спасибо за вашу помощь!
//Редактировать:
Сначала я не заметил, но получаю аудио, а не видео.
3 ответа
Итак, я решил это после некоторого поиска на этой странице, я нашел что-то вроде 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"
}
}
Для справки, вы можете заменить все эти функции 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"
}
}
Мой код показан ниже
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"
}
}