-
Notifications
You must be signed in to change notification settings - Fork 58
/
gst_device_to_rtp.py
42 lines (34 loc) · 967 Bytes
/
gst_device_to_rtp.py
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
import time
import cv2
# Cam properties
fps = 30.
frame_width = 640
frame_height = 480
# Create capture
cap = cv2.VideoCapture(0)
# Set camera properties
cap.set(cv2.CAP_PROP_FRAME_WIDTH, frame_width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_height)
cap.set(cv2.CAP_PROP_FPS, fps)
# Define the gstreamer sink
gst_str_rtp = "appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000"
# Check if cap is open
if cap.isOpened() is not True:
print "Cannot open camera. Exiting."
quit()
# Create videowriter as a SHM sink
out = cv2.VideoWriter(gst_str_rtp, 0, fps, (frame_width, frame_height), True)
# Loop it
while True:
# Get the frame
ret, frame = cap.read()
# Check
if ret is True:
# Flip frame
frame = cv2.flip(frame, 1)
# Write to SHM
out.write(frame)
else:
print "Camera error."
time.sleep(10)
cap.release()