RTSP OpenCV Too Short Data and other errors
Hi,
I'm fairly new to OpenCV but want to do a fairly simple task. Open my 5 CCTV cameras using VideoCapture and display them.
Here's the code that I have:
from threading import Thread
import imutils
import cv2, time
import argparse
import numpy as np
import datetime
camlink1 = "rtsp://cam1"
camlink2 = "rtsp://cam2"
camlink3 = "rtsp://cam3"
camlink4 = "rtsp://cam4"
camlink5 = "rtsp://cam5"
class VideoStreamWidget(object):
def __init__(self, link, camname, src=0):
self.capture = cv2.VideoCapture(link)
# Start the thread to read frames from the video stream
self.thread = Thread(target=self.update, args=())
self.thread.daemon = True
self.thread.start()
self.camname = camname
self.link = link
print(camname)
print(link)
print("[INFO] Warming up...")
def update(self):
# Read the next frame from the stream in a different thread
while True:
if self.capture.isOpened():
(self.status, self.frame) = self.capture.read()
time.sleep(.5)
def show_frame(self):
#Grab the frame dimensions and convert it to a blob
frame = imutils.resize(self.frame, width=400)
(h, w) = frame.shape[:2]
# Display frames in main program
cv2.imshow('Frame ' + self.camname, frame)
key = cv2.waitKey(1)
if key == ord('q'):
self.capture.release()
cv2.destroyAllWindows()
exit(1)
#time.sleep(.05)
if __name__ == '__main__':
video_stream_widget = VideoStreamWidget(camlink1,"Cam1")
video_stream_widget2 = VideoStreamWidget(camlink2,"Cam2")
video_stream_widget3 = VideoStreamWidget(camlink3,"Cam3")
video_stream_widget4 = VideoStreamWidget(camlink4,"Cam4")
video_stream_widget5 = VideoStreamWidget(camlink5,"Cam5")
while True:
try:
video_stream_widget.show_frame()
video_stream_widget2.show_frame()
video_stream_widget3.show_frame()
video_stream_widget4.show_frame()
video_stream_widget5.show_frame()
except AttributeError as e:
print("[INFO] Stream Failed" + str(e) +"...")
pass
The links are all correct and working - i've hide them for security. Also I can connect using an external camera viewer app on my phone and they stream perfectly for hours on end.
When I run the code in python it starts fine and runs for a minute or two, but then I start and get these messages:
[h264 @ 0x29aee40] left block unavailable for requested intra4x4 mode -1 [h264 @ 0x29aee40] error while decoding MB 0 28, bytestream 102031 [h264 @ 0x14a7e40] left block unavailable for requested intra mode [h264 @ 0x14a7e40] error while decoding MB 0 32, bytestream 36606 [rtsp @ 0x170dac0] Too short data for FU-A H.264 RTP packet [rtsp @ 0x17344c0] Too short data for FU-A H.264 RTP packet [h264 @ 0x2b715c0] cabac decode of qscale diff failed at 18 49 [h264 @ 0x2b715c0] error while decoding MB 18 49, bytestream 62817
Then all previews just stop.
OpenCV is the latest version and In useing python3.7 too on Ubuntu 16.04
Can anyone point me in the right direction please?
Cheers Chris