问题
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);
}
}
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.
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
EDIT 1
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";
}
and instantiate it with the following line
m_video_stream= new VideoStreaming(ui->m_video);
m_video_stream->init(m_player);
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.
回答1:
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");
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
来源:https://stackoverflow.com/questions/65159652/how-to-stream-the-video-using-vlc-qt-wrapper