-
Notifications
You must be signed in to change notification settings - Fork 58
/
gst_device_to_shm.py
41 lines (34 loc) · 935 Bytes
/
gst_device_to_shm.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
import time
import cv2
# Cam properties
fps = 30.
frame_width = 1920
frame_height = 1080
# 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 = "appsrc ! videoconvert ! shmsink socket-path=/tmp/foo sync=true wait-for-connection=false shm-size=10000000"
# 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, 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()