Hello,
We have a video analytics solution for real time CCTV analytics. This product connects to CCTV in realtime over RTSP feed using GStreamer and OpenCV.
The product is built using Python.
** Problem Statement **
- RTSP Stream: An example RTSP video_source is: ‘rtsp://admin:admin12345@192.168.0.103/live’
- The URI that we construct is as follows
uri = f"rtspsrc location={self.video_source} latency=0 ! decodebin ! videoconvert ! video/x-raw, format=BGR ! videoscale ! video/x-raw, width={self.frame_width}, height={self.frame_height} ! appsink"
-
We open connection through URI using opencv as follows:
cap = cv2.VideoCapture(uri) -
We get frames from this cap object as:
ret, frame = cap.read()
We are facing a problem that this process is very CPU intensive. On an i7-10th generation processor, the CPU is 100% utilized for just 10 camera streams.
We debugged and found out that decodebin and appsink in the overall pipeline are both RAM and CPU intensive.
Our OpenCV is built with Gstreamer.
** Search for a solution **
When we started to search a solution, we read this blog post: How to install Nvidia Gstreamer plugins (nvenc, nvdec) on Ubuntu? - LifeStyleTransfer
and understood that a NVDEC plugin will help a lot reducing the CPU. We were able to follow the steps in this blog post.
We then looked at this post to use Gstreamer to completely bypass OpenCV and directly get the frames from GStreamer for inference.
We were able to make this work as well. We followed code from GitHub - jackersson/gst-python-tutorials as mentioned in the blog post. We are able to get individual frames as mentioned in the blog:
array = np.ndarray(shape=(h, w, c), buffer=buffer.extract_dup(0, buffer.get_size()), dtype=utils.get_np_dtype(video_format))
** Still not able to solve **
However, we are not able to use both NVDEC and Gstreamer in python together. In order to get the frames in python, we are unable to bypass appsink, which we believe is the main culprit here.