Problem in reading the frames continuously using gstreamer pipeline

I am reading the drone camera using the opencv Videocapture gstreamer and adding an overlay text to the frame.

The python script can read the frames and add an overlay, and I using nvv4l2decoder to decode the frames. But after minutes, the frame returns None and the gstreamer reader pipeline stops to read the data.

import cv2


cap_send = cv2.VideoCapture('rtspsrc location="rtsp://192.168.0.201:5500/live0"  !  queue max-size-bytes=65536 max-size-buffers=0 max-size-time=0 leaky=downstream ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink sync=false ')


scale = 1
font = cv2.FONT_HERSHEY_PLAIN
xMargin = 10
yMarginBottom = 10
yMarginTop = 20


while True:
    try:
        time.sleep(0.03)
        ret,frame = cap_send.read()
        if not ret:
            print('empty frame')
            #break
        cv2.imshow('frame', frame)
        if cv2.waitKey(1)&0xFF == ord('q'):
            break
    except Exception as e:
        print (e)

cap_send.release()
out_send.release()

I am getting this error If I move the camera continuously for few minutes. My camera is integrated with a drone, so when the vehicle is flying it sends the frame and suddenly gstreamer pipelines stops sending the frames.

After the below error, the pipeline stops to read.

Hi,
It looks like the source is not stable and in the case it cannot generate valid h264 stream. Please also try gst-launch-1.0 command like:

$ gst-launch-1.0 rtspsrc location="rtsp://192.168.0.201:5500/live0"  !  queue max-size-bytes=65536 max-size-buffers=0 max-size-time=0 leaky=downstream ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw,format=BGR ! fakesink

To clarify if it is specific to using cv2.VideoCapture().

@DaneLLL

I am getting the similar error with fakesink.

I tried the push the same stream to RTMP via ffmpeg. I don’t have an issue in sending the stream.

Hi,
Please remove the queue plugin and try. Looks like some properties is set in queue plugin and in certain conditions packets may be dropped instead of sending to decoder.

@DaneLLL

I am getting the same error after removing the queue plugin. Is there a way to skip invalid frames or keep the pipeline open for next frame.