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_file.py
44 lines (35 loc) · 1.44 KB
/
gst_intel_device_to_app_to_file.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
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
appsink2file = "appsrc ! videoconvert ! mfxh264enc ! \
video/x-h264, profile=baseline ! \
matroskamux ! filesink location=the_gstreamer_enjoyer.mkv"
# 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(appsink2file, 0, fps, (frame_width, frame_height), True)
if not cap.isOpened():
print("Cannot capture from camera. Exiting.")
quit()
if not out:
print("Cannot write. Exiting.")
quit()
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