-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsender.cpp
More file actions
55 lines (41 loc) · 1.76 KB
/
Copy pathsender.cpp
File metadata and controls
55 lines (41 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
void sender()
{
// VideoCapture: Getting frames using 'v4l2src' plugin, format is 'BGR' because
// the VideoWriter class expects a 3 channel image since we are sending colored images.
// Both 'YUY2' and 'I420' are single channel images.
// VideoCapture cap("v4l2src device=\"/dev/video0\" ! video/x-raw,width=640,height=480,framerate=15/1 ! videoscale ! videoconvert ! appsink",cv::CAP_GSTREAMER);
std::string options = "v4l2src device=\""+devName+"\" ! video/x-raw,width="+std::to_string(w)+",height="+std::to_string(h)+\
",framerate="+std::to_string(fps)+"/1 ! videoscale ! videoconvert ! appsink";
cv::VideoCapture cap(options,cv::CAP_GSTREAMER);
// VideoWriter: 'videoconvert' converts the 'BGR' images into 'YUY2' raw frames to be fed to
// 'jpegenc' encoder since 'jpegenc' does not accept 'BGR' images. The 'videoconvert' is not
// in the original pipeline, because in there we are reading frames in 'YUY2' format from 'v4l2src'
VideoWriter out("appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=1000 speed-preset=superfast ! rtph264pay ! udpsink host=192.168.10.13 port=5000",CAP_GSTREAMER,0,20,Size(640,480),true);
if(!cap.isOpened() || !out.isOpened())
{
if (!out.isOpened())
cout<<"out not opened"<<endl;
cout<<"VideoCapture or VideoWriter not opened"<<endl;
exit(-1);
}
Mat frame;
while(true) {
cap.read(frame);
//imshow("Sender", frame);
if(frame.empty())
break;
out.write(frame);
if(waitKey(1) == 's')
break;
}
destroyWindow("Sender");
}
int main()
{
sender();
return 0;
}