Search code examples
c++qmlvlc-qt

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.


Solution

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