Nvdec in Gstreamer pipeline fails

I am trying to utilize the GPU decoder to handle my rtsp stream in OpenCV, this pipeline is currently failing.

cap = cv2.VideoCapture('rtspsrc location=rtsp://localhost:8554/ ! rtph264depay ! h264parse ! nvdec ! videoconvert ! appsink', cv2.CAP_GSTREAMER)

The failing message is listed as follow:

(python3:48928): GStreamer-CRITICAL **: 17:00:08.155:
Trying to dispose element nvdec0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(python3:48928): GStreamer-CRITICAL **: 17:00:08.155:
Trying to dispose element h264parse0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(python3:48928): GStreamer-CRITICAL **: 17:00:08.155:
Trying to dispose element rtph264depay0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(python3:48928): GStreamer-CRITICAL **: 17:00:08.155:
Trying to dispose element rtpstorage0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(python3:48928): GStreamer-CRITICAL **: 17:00:08.155:
Trying to dispose element funnel1, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(python3:48928): GStreamer-CRITICAL **: 17:00:08.155:
Trying to dispose element funnel0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(python3:48928): GStreamer-CRITICAL **: 17:00:08.155:
Trying to dispose element manager, but it is in PLAYING (locked) instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(python3:48928): GStreamer-CRITICAL **: 17:00:08.155:
Trying to dispose element rtspsrc0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

When I set GST_DEBUG=4, I am able to see this error:

0:00:00.275478672 48840 0x7fdbfc003a30 INFO               GST_EVENT gstevent.c:1517:gst_event_new_reconfigure: creating reconfigure event
0:00:00.275507575 48840 0x7fdbfc003a30 WARN                   nvdec gstnvdec.c:61:cuda_OK: CUDA call failed: CUDA_ERROR_INVALID_HANDLE, invalid resource handle
0:00:00.275515327 48840 0x7fdbfc003a30 WARN                   nvdec gstnvdec.c:1000:gst_nvdec_drain:<nvdec0> parser failed
0:00:00.275526125 48840 0x7fdbfc003a30 FIXME               basesink gstbasesink.c:3145:gst_base_sink_default_event:<appsink0> stream-start event without group-id. Consider implementing group-id handling in the upstream elements

Hey I’m facing the same issue, have you found any solution for this?

No I have not. Still waiting for a reply. Will post the solution here once I figure it out.

Did you ever find a solution to this issue? I’m having the same issue. David

unfortunately no. If you have made any progress, please let us know. :)

I think you can try to capture the bus message Gst.MessageType.EOS and Gst.MessageType.ERROR, then set the pipeline state to NULL like this:

pipeline.set_state(Gst.State.NULL)

It means your pipeline meet the end of stream, or an error occurred. We can reinit our stream pipeline to receive rtsp stream data. It’s my solusion , and it worked.
You should use gstreamer directly instand of opencv, and convert the gst result to numpy array, finally show with opencv. a reference code link: GStreamer-Python/vid_streamv3.py at master · sahilparekh/GStreamer-Python · GitHub

        # init and playing pipeline 

        # Wait until error or EOS
        bus = self.pipeline.get_bus()

        while True:

            wait_time = Gst.SECOND # 1s
            message = bus.timed_pop_filtered(wait_time, Gst.MessageType.ANY)

            if message is None:
                continue
            if message.type == Gst.MessageType.ERROR:
                err, debug = message.parse_error()
                print("Error received from element %s: %s" % (
                    message.src.get_name(), err))
                self.pipeline.set_state(Gst.State.NULL)
                # reinit and playing pipeline , update bus reference
            elif message.type == Gst.MessageType.EOS:
                print("End-Of-Stream reached.")
                self.pipeline.set_state(Gst.State.NULL)
                # reinit and playing pipeline , update bus reference