0

I am attempting to use gstreamer in order to convert my OpenCV frames into a rtp stream, but I have trouble even opening up the webcam and other files.

I was having trouble with getting my script to work well, so I ran this:

export OPENCV_VIDEOIO_DEBUG=TRUE

This is the code that I used:

# Cam properties
fps = 30.
cap = cv2.VideoCapture(0)

# Set camera properties
frame_width = cv2.CAP_PROP_FRAME_WIDTH
frame_height = cv2.CAP_PROP_FRAME_HEIGHT

cap.set(cv2.CAP_PROP_FPS, fps)

# Define the gstreamer sink
gst_str_rtp = "appsrc ! videoconvert ! x264enc noise-reduction=10000 tune=zerolatency byte-stream=true threads=4 ! h264parse ! mpegtsmux ! rtpmp2tpay ! 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)

I get this error every time I try to run it:

[ WARN:0] VIDEOIO(cvCreateCameraCapture_V4L(index)): trying ...

[ WARN:0] VIDEOIO(cvCreateCameraCapture_V4L(index)): result=0x1f5a7a0 ...

[ WARN:0] VIDEOIO(cvCreateVideoWriter_FFMPEG_proxy(filename, fourcc, fps, frameSize, isColor)): trying ...

Segmentation fault (core dumped)

What should I do?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3377126
  • 2,091
  • 4
  • 32
  • 39

1 Answers1

0

You will need to initialize the VideoWriter with the GSTREAMER parameters as such.

out = cv2.VideoWriter(gst_str_rtp, cv2.CAP_GSTREAMER, 0, fps, (frame_width, frame_height), True)