C++ 使用RTSP从Opencv处理后,从PC将视频流传输到Android
我正在尝试在opencv中处理后,将两个网络摄像头的组合视频流传输到android应用程序(组合两帧) 在这里,我尝试使用RTSP将视频流从opencv发送到Android(使用gstreamer管道) 但我一直在研究如何将.sdp文件配置发送到客户端(文件名为live.sdp),下面是我目前使用的代码C++ 使用RTSP从Opencv处理后,从PC将视频流传输到Android,c++,opencv,streaming,gstreamer,rtsp,C++,Opencv,Streaming,Gstreamer,Rtsp,我正在尝试在opencv中处理后,将两个网络摄像头的组合视频流传输到android应用程序(组合两帧) 在这里,我尝试使用RTSP将视频流从opencv发送到Android(使用gstreamer管道) 但我一直在研究如何将.sdp文件配置发送到客户端(文件名为live.sdp),下面是我目前使用的代码 //basic #include <iostream> #include <stdio.h> #include <stdio.h> #include <
//basic
#include <iostream>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
//opencv libraries
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main(int argc,char **argv){
Mat im1;
Mat im2;
VideoCapture cap1(1);
VideoCapture cap2(2);
VideoWriter video;
video.open("appsrc ! videoconvert ! x264enc noise-reduction=10000 tune=zerolatency byte-stream=true threads=4 ! mpegtsmux ! rtpmp2tpay send-config=true config-interval=10 pt=96 ! udpsink host=localhost port=5000 -v"
, 0, (double)20,Size(1280, 480), true);
if(video.isOpened()){
cout << "Video Writer is opened!"<<endl;
}else{
cout << "Video Writer is Closed!"<<endl;
return -1;
}
while(1){
cap1.grab();
cap2.grab();
bool bSuccess1 = cap1.read(im2);
bool bSuccess2 = cap2.read(im1);
Size sz1 = im1.size();
Size sz2 = im2.size();
Mat im3(sz1.height, sz1.width+sz2.width, CV_8UC3);
Mat left(im3, Rect(0, 0, sz1.width, sz1.height));
im1.copyTo(left);
Mat right(im3, Rect(sz1.width, 0, sz2.width, sz2.height));
im2.copyTo(right);
video << im3;
//imshow("im3", im3);
if(waitKey(10) == 27){
break;
}
}
cap1.release();
cap2.release();
video.release();
return 0;
}
我可以在本地文件夹中播放vlc中的流,
使用
但不是在网络内部,通过使用
vlc rtsp://localhost:5000/live.sdp
使用Gstreamer和opencv解决了这个问题,但仍然有小的滞后
vlc live.sdp
vlc rtsp://localhost:5000/live.sdp