VideoCapture GStreamer not releasing connection to nvargus

Hello,

I’m using OpenCV in Python3 within a Linux Docker container. I’m capturing video in OpenCV with VideoCapture() and GStreamer like so:

cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=3840, height=2160, framerate=60/1 ! nvvidconv ! video/x-raw, format=(string)I420, width=3840, height=2160 !  appsink", cv2.CAP_GSTREAMER)

This works well except sometimes nvargus has issues and needs to be restarted. I do this from the host system using systemctl restart nvargus-daemon. Before restarting nvargus, I release the VideoCapture instance. This results in VideoCapture never working again in the Python instance without restarting python.

After releasing VideoCapture and restarting nvrargus I get the following error in my docker container:

(Argus) Error EndOfFile: Unexpected error in reading socket (in src/rpc/socket/client/ClientSocketManager.cpp, function recvThreadCore(), line 266)
(Argus) Error EndOfFile: Receiving thread terminated with error (in src/rpc/socket/client/ClientSocketManager.cpp, function recvThreadWrapper(), line 368)

Dmesg:

Stopping NVIDIA Argus daemon...
CAM: serial no file already exists, skips storing again
nvargus-daemon.service: Succeeded.
Stopped NVIDIA Argus daemon.
Started NVIDIA Argus daemon.

Attempting to open the VideoCapture again with

capture.open(gst_pipeline, cv2.CAP_GSTREAMER)

results in this error:

(Argus) Error InvalidState: Receive thread is not running cannot send. (in src/rpc/socket/client/ClientSocketManager.cpp, function send(), line 96)
(Argus) Error InvalidState:  (propagating from src/rpc/socket/client/SocketClientDispatch.cpp, function dispatch(), line 87)

The only fix to get gst working with VideoCapture again is to restart Python.
How can I close the VideoCapture correctly so I can restart nvargus then open VideoCapture again to be used?

OpenCv Version: OpenCV 4.5.0
GStreamer Version: 1.14.5

I still haven’t resolved this.

same problem using a console gstreamer cmdline ?
(if so, there’s no way to repair it from opencv)

Well I’m not sure how I could replicate it from the command line. I’d need to release gst while it’s running and continue it again once nvargus is restarted.

What I can do is launch a gst pipeline then stop it, restart nvargus from host, and then launch gst again and it’ll work fine.

It seems like the issue is VideoCapture in Python because if I restart Python, it’ll start working again. It’s like VideoCapture.release() isn’t doing all that it should.