Brykyz
Brykyz

Reputation: 657

Play RTSP video with Qt VLC libary in C++

I am trying to connect my VlcVideoPlayer from VLCQt libary to any video streamed from url with rts protocol.

Currently, this is my code:

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
}

It works with https:// , but when I try to change it to rtps://, my console only prints out

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

and nothing happens - no video shows up.

When I tried to show current time of video with console.log(time), time was changing so I guess it plays video, but it doesn't show up.

Anyone have experience with this? Where am I doing mistake?

Thanks for your help!

//Edit:

I didn't notice first, but I am getting audio, but not video.

Upvotes: 3

Views: 2885

Answers (3)

Wagner Volanin
Wagner Volanin

Reputation: 97

For reference, you can replace all these qmlRegister() functions with:

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

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

And

import VLCQt 1.1

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

Upvotes: 0

Ganwell JB Banda
Ganwell JB Banda

Reputation: 11

My code is as shown below

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

Upvotes: 0

Brykyz
Brykyz

Reputation: 657

So, I have solved it after some searching on this page, I have found something like VlcQmlPlayer, functions are almost same as in VlcQmlVideoPlayer, except it's newer and it's source is subclass of VlcQmlVideoOutput. So I registered few types for 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");

and after that, I used it in QML like this

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

Upvotes: 2

Related Questions