我如何使用OpenCV创建一个简单的C++程序,使用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端口= 5000
!应用程序/x-rtp,媒体=视频,时钟速率= 90000,编码名称= JPEG,有效负载= 26
返回
! jpegdec
! xvimagesink同步= 0 *
但是,它不能使用rtsp://127.0.0.1:5000 URL通过VLC打开
1条答案
按热度按时间kqlmhetl1#
我有一个解决方案。这是代码的改进版本
现在,问题是这不是由像vcl这样的程序直接读取的,你需要同时运行rtsp-simple-server的一个示例(你可以下载不依赖here的二进制文件)
看起来opencv编写器将数据发送到rtsp-simple-server,后者将数据流重定向到请求它的rtsp客户机。
最后,转到vlc并打开url rtsp://localhost:8554/mystream