forked from mad4ms/python-opencv-gstreamer-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gst_intel_device_to_app_to_rtp.py
57 lines (43 loc) · 1.79 KB
/
gst_intel_device_to_app_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import cv2
# Funny note. If you exec "export GST_DEBUG=4" and then try something like displaying your webcam on the autovideosink
# like this "gst-launch-1.0 v4l2src ! videoconvert ! autovideosink", the debug spits out all possible caps that you
# can actually copy and paste. (caps are the preferences for the cam .. the video/x-raw , format, res and stuff.
# The following string usually works on most webcams
webcam2appsink_YUY2_640_480 = "v4l2src device=/dev/video0 ! video/x-raw, format=YUY2, width=640, height=480, pixel-aspect-ratio=1/1, framerate=30/1 ! videoconvert ! appsink"
# mfxh264enc does all the HW encoding
appsink2rtp_IntelMFX = "appsrc ! videoconvert ! mfxh264enc ! \
video/x-h264, stream-format=byte-stream, profile=baseline ! \
rtph264pay pt=96 ! udpsink host=127.0.0.1 port=5004"
# Multipass, ehm, multiCAST
# appsink2rtp_IntelMFX_multi = "appsrc ! videoconvert ! mfxh264enc ! \
# video/x-h264, stream-format=byte-stream, profile=baseline ! \
# rtph264pay pt=96 ! udpsink host=239.255.0.1 port=5004 auto-multicast=true
# Open the capture string
cap = cv2.VideoCapture(webcam2appsink_YUY2_640_480)
# Hardcoded image properties. Mind here to change them to your needs.
frame_width = 640
frame_height = 480
fps = 30.
show = True
# Create videowriter
out = cv2.VideoWriter(appsink2rtp_IntelMFX, 0, fps,
(frame_width, frame_height), True)
# Check cam
if not cap.isOpened():
print("Cannot capture from camera. Exiting.")
quit()
# Check writer
if not out:
print("Cannot write. Exiting.")
quit()
# Go
while True:
ret, frame = cap.read()
#
if ret == False:
break
out.write(frame)
if show:
cv2.imshow("the_gstreamer_enjoyer", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break