gstreamer rtsp流不能使用VLC读取,但可以从另一个gstreamer实例读取



我如何创建一个简单的c++程序使用OpenCV流使用rstp,使它可以看到使用vlc?我一直在寻找许多例子,但没有一个工作。

感谢例如:

int main()
{
VideoCapture cap(0);
if (!cap.isOpened()) {
cerr <<"VideoCapture not opened"<<endl;
exit(-1);
}
VideoWriter writer(
"appsrc ! videoconvert ! video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000",
0,      // fourcc
30,     // fps
Size(640, 480),
true);  // isColor
if (!writer.isOpened()) {
cerr <<"VideoWriter not opened"<<endl;
exit(-1);
}
while (true) {
Mat frame;
cap.read(frame);
writer.write(frame);
}
return 0;
}

可以使用命令行

读取视频馈送gst-launch-1.0 -v udpsrc port=5000
!application/x-rtp, media=video, clock-rate=90000, encoding-name=JPEG, payload=26
!
!Jpegdec
!xvimagesink同步= 0

然而,它不能VLC使用rtsp://127.0.0.1:5000URL

我有办法了。下面是代码

的改进版本
#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
int main()
{
VideoCapture cap("/home/salinas/Descargas/Minions/Minions.avi"); // video file input
if (!cap.isOpened())
{
std::cout << "Video Capture Fail" << std::endl;
return 0;
}
VideoWriter writer;
// Write this string to one line to be sure!!
writer.open("appsrc ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! x264enc speed-preset=veryfast tune=zerolatency bitrate=800 ! rtspclientsink location=rtsp://localhost:8554/mystream ",
0, 20, Size(640, 480), true);
// Comment this line out
Mat img;
while(cap.read(img))
{
cv::resize(img, img, Size(640, 480));
cv::imshow("raw", img);
writer << img;
cv::waitKey(25);
}

现在,问题是它不能被vcl这样的程序直接读取。您需要同时运行rtsp-simple-server的一个实例(您可以在这里下载依赖的二进制文件)

似乎opencv编写器将数据发送到rtsp-simple-server, rtsp-simple-server将流重定向到请求它的rtsp客户端。

最后,进入vlc,打开url rtsp://localhost:8554/mystream