我在Ubuntu上的OpenCV 4.4.0.46中捕获并处理了一个IP相机RTSP流。不幸的是,处理过程花费了相当长的时间,大约每帧0.2s,而且流很快就会延迟。视频文件必须保存5分钟,但通过此延迟视频文件仅保存3-4分钟。
我们能否更快地处理以克服延误?
我有两个IP相机,它有两个不同的fps_rate(照相机1有18000,照相机2有20 fps)。
我正在不同的Ubuntu个人电脑上实现这个代码。
linux
上的
input_stream = 'rtsp://'+username+':'+password+'@'+ip+'/user='+username+'_password='+password+'_channel=0channel_number_stream=0.sdp'
input_stream---> rtsp://admin:Admin123@192.168.1.208/user=admin_password=Admin123_channel=0channel_number_stream=0.sdp
input_stream---> rtsp://Admin:@192.168.1.209/user=Admin_password=_channel=0channel_number_stream=0.sdp
vs = cv2.VideoCapture(input_stream)
fps_rate = int(vs.get(cv2.CAP_PROP_FPS))
I have two IP camera which have two diffrent fps_rate(Camera 1 have 18000 and camera 2 have 20 fps)
video_file_name = 0
start_time = time.time()
while(True):
ret, frame = vs.read()
time.sleep(0.2) # <= Simulate processing time (mask detection, face detection and many detection is hapning)
### Start of writing a video to disk
minute = 5 ## saving a file for 5 minute only then saving another file for 5 min
second = 60
minite_to_save_video = int(minute) * int(second)
# if we are supposed to be writing a video to disk, initialize
if time.time() - start_time >= minite_to_save_video or video_file_name == 0 :
## where H = heigth, W = width, C = channel
H, W, C = frame.shape
print('time.time()-->',time.time(),'video_file_name-->', video_file_name, ' #####')
start_time = time.time()
video_file_name = str(time.mktime(datetime.datetime.now().timetuple())).replace('.0', '')
output_save_directory = output_stream+str(int(video_file_name))+'.mp4'
fourcc = cv2.VideoWriter_fourcc(*'avc1')
writer = cv2.VideoWriter(output_save_directory, fourcc,20.0,(W, H), True)
# check to see if we should write the frame to disk
if writer is not None:
try:
writer.write(frame)
except Exception as e:
print('Error in writing video output---> ', e)发布于 2021-03-18 14:36:57
我看到了处理这件事的两种选择。
https://stackoverflow.com/questions/66687813
复制相似问题