如何使用 VLC-QT 包装器流式传输视频 [英] How to stream the video using VLC-QT wrapper

查看:59
本文介绍了如何使用 VLC-QT 包装器流式传输视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 RTSP、HTTP 和 UDP 流式传输视频,因为 vlc 支持它们.我正在使用 Qt5 并且由于 Qt 没有那么多好的媒体库,所以我选择开源,现在使用 libvlc 通过 >VLC-Qt 包装器.

I want to stream the video using RTSP, HTTP and UDP as they are supported by vlc. I am using Qt5 and as Qt don't have that much good media libraries so I go for open source and now using libvlc through VLC-Qt wrapper.

我可以在我的程序中接收流视频,下面给出了接收流视频的源代码

I am able to receive the stream videos in my program, The source code for receiving the streaming video is given below

void player::on_actionNETWORK_STREAM_triggered()
{
    QString url= QInputDialog::getText(this,tr("Open Url"),tr("Enter the URL you want to play"));

    if(url.isEmpty())
        return;
    else
    {
        m_media=new VlcMedia(url,m_instance);
        playlist.append(url);
        m_mediaList->addMedia(m_media);
        m_player->open(m_media);
    }
}

为了接收流媒体视频,我只是将该视频的 url 放入新的 VlcMedia 实例中,但不知道如何流式传输视频.

To receive the streaming video I just put the url of that video into the new VlcMedia instance but don't know how to stream a video.

在阅读 VLC-QT 包装器的文档时,我读到它有一个名为 VlcVideoStream class 但我不知道如何使用该类进行流式传输.这个class的文档链接如下

While reading the documentation of the VLC-QT wrapper I read that it have one class named VlcVideoStream but I am not getting how to use that class to do the streaming. The link of the documentation of this class is given below

https://vlc-qt.tano.si/reference/1.1/classvlcvideostream

编辑 1

我在互联网上搜索了更多关于这件事的信息,然后我发现了一些关于如何使用 VlcVideoStream 的讨论,我已经实现了代码.源代码如下

I searched on the internet more about this thing then I found some discussion of how to use VlcVideoStream and I have implemented the code for that. The source code is given below

class VideoStreaming : public VlcVideoStream
{
    Q_OBJECT
public:
    explicit VideoStreaming(QObject *parent = nullptr);

    void frameUpdated();
};

void VideoStreaming::frameUpdated()
{
    int rows,cols;
    
    std::shared_ptr<const VlcAbstractVideoFrame>  frame=  renderFrame();
    
    if (!frame)
        return; // LCOV_EXCL_LINE

    
    rows = frame->height + frame->height/2;
    cols = frame->width;
    
    qDebug()<<"Frame updated gets called";
}

并使用以下行实例化它

    m_video_stream= new VideoStreaming(ui->m_video);
    m_video_stream->init(m_player);

现在我可以接收视频的 YUV 帧,但直到现在我还不知道如何流式传输视频.任何帮助表示赞赏.即使我对纯 libvlc 流媒体解决方案持开放态度,因为 VLC-QT 包装器并不是支持视频流的好包装器.

Now I am able to receive the YUV frames of the video but don't know how to stream the video till now. Any help is appreciated. Even I am open to the pure libvlc streaming solution as VLC-QT wrapper is not that much good wrapper to support video streaming.

推荐答案

我只是使用了 VlcMediasetOption() 函数来设置流媒体属性,它可以工作.

I just use the setOption() function of VlcMedia to set the streaming attributes and it works.

    m_media = new VlcMedia("file:///home/vinay/Media Library/lion-sample.webm",m_instance);
    m_media->setOption(":sout=#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:udp{dst=127.0.0.1:1234}");
    m_media->setOption(":no-sout-all");
    m_media->setOption(":sout-keep");

那些字符串参数取自 vlc 应用程序.当我们通过 vlc 应用程序流式传输视频时,它会在最后一个窗口中显示您设置的所有这些参数.所以我只是复制这些参数并将其作为参数传递给 setOption() 并且它有效.

Those string arguments are taken from the vlc application. When we stream the video through vlc application, In the last window it show all of these parameters which you set. So i just copy those parameters and passed it as an argument to the setOption() and It works.

您可以在此链接中阅读我对此主题的详细讨论

You can read my detailed discussion of this topic in this link

https://forum.qt.io/topic/121483/how-to-stream-the-video-using-vlc-qt-wrapper-or-libvlc/10

这篇关于如何使用 VLC-QT 包装器流式传输视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆