Hi there,
I’m attempting to add a gstreamer capture and output to my python script utilising open CV but I’m struggling to find success.
cap = cv2.VideoCapture('v4l2src device=“/dev/video0” ! “video/x-raw, width=640, height=480, format=(string)YUY2” ! videoconvert ! video/x-raw, format=(string)BGR ! appsink ', cv2.CAP_GSTREAMER)
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
print(‘Src opened, %dx%d @ %d fps’ % (w, h, fps))gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw,format=BGRx ! nvvidconv ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=test.mkv "
out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(30), (int(640), int(480)))
if not out.isOpened():
print(“Failed to open Output”)
exit()
This will output
Src opened, 0x0 @ 0 fps
Failed to open Output
The USB camera is setup and working. If I run the following in terminal the camera displays as expected:
gst-launch-1.0 v4l2src device=“/dev/video0” !
“video/x-raw, width=640, height=480, format=(string)YUY2” !
xvimagesink -e
OpenCV 4.5 has been install via the AastaNV installation script with both Gstreamer and CUDA support.
Any assistance would be much appreciated.