Code with huge latency issues while streaming
import cv2
camera = cv2.VideoCapture(("rtsp://admin:123456@192.168.10.57/stream0"),cv2.CAP_V4L)
if not camera.isOpened():
raise RuntimeError('Could not start camera.')
while 1:
_, img = camera.read()
cv2.imshow('ImageWindow', img)
Tried to add 0 latency
import cv2
camera = cv2.VideoCapture(("rtsp://admin:123456@192.168.10.57/stream0"),cv2.CAP_V4L)
if not camera.isOpened():
raise RuntimeError('Could not start camera.')
while 1:
_, img = camera.read()
cv2.imshow('ImageWindow', img)
Got the following error
VIDEOIO ERROR: V4L: device rtspsrc location=rtsp://admin:123456@192.168.10.57/stream0 latency=0 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, width=(int)1920, height=(int)1080, format=(string)BGRx ! videoconvert ! appsink: Unable to query number of channels
Tried to add GStreamer to speed up streaming
import cv2
rtsp_url = "rtsp://admin:123456@192.168.10.57/stream0"
gst_str = ('rtspsrc location={} latency={} ! '
'rtph264depay ! h264parse ! omxh264dec ! '
'nvvidconv ! '
'video/x-raw, width=(int){}, height=(int){}, '
'format=(string)BGRx ! '
'videoconvert ! appsink').format(rtsp_url, 0, 1920, 1080)
print("Running RTSP Camera with url:", self.rtsp_url)
camera = cv2.VideoCapture(gst_str, cv2.CAP_V4L)
if not camera.isOpened():
raise RuntimeError('Could not start camera.')
while 1:
_, img = camera.read()
cv2.imshow('ImageWindow', img)
Error Log
(python:6469): GStreamer-CRITICAL \**: 11:05:30.499: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed**
Exception in thread Thread-1: