how to use gstreamer pipeline in opencv 3f

Solutions on MaxInterview for how to use gstreamer pipeline in opencv 3f by the best coders in the world

showing results for - "how to use gstreamer pipeline in opencv 3f"
Sofia
14 Oct 2016
1"""https://answers.opencv.org/question/202017/how-to-use-gstreamer-pipeline-in-opencv/"""
2
3def send():
4    cap_send = cv2.VideoCapture('videotestsrc ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
5    out_send = cv2.VideoWriter('appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000',cv2.CAP_GSTREAMER,0, 20, (320,240), True)
6
7    if not cap_send.isOpened() or not out_send.isOpened():
8        print('VideoCapture or VideoWriter not opened')
9        exit(0)
10
11    while True:
12        ret,frame = cap_send.read()
13
14        if not ret:
15            print('empty frame')
16            break
17
18        out_send.write(frame)
19
20        cv2.imshow('send', frame)
21        if cv2.waitKey(1)&0xFF == ord('q'):
22            break
23
24    cap_send.release()
25    out_send.release()
26
27def receive():
28    cap_receive = cv2.VideoCapture('udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
29
30    if not cap_receive.isOpened():
31        print('VideoCapture not opened')
32        exit(0)
33
34    while True:
35        ret,frame = cap_receive.read()
36
37        if not ret:
38            print('empty frame')
39            break
40
41        cv2.imshow('receive', frame)
42        if cv2.waitKey(1)&0xFF == ord('q'):
43            break
44
45    #cap_receive.release()
46
47if __name__ == '__main__':
48    s = Process(target=send)
49    r = Process(target=receive)
50    s.start()
51    r.start()
52    s.join()
53    r.join()
54
55    cv2.destroyAllWindows()