首页 > 解决方案 > 如何以低 CPU 使用率从 OpenCV 读取 RTSP 视频?

问题描述

import numpy as np
import cv2

cap = cv2.VideoCapture("rtsp://admin:admin123@10.0.51.110/h264/ch3/main/av_stream")
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Processing Frame -
    # Running Computer Vision Algorithm

    # Display the resulting frame
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
       break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

此代码使用了附近 50% 的 CPU 使用率。我们如何减少这种 CPU 使用率?
我使用了 time.sleep(0.05) 但它延迟了视频馈送处理,所以对我来说不会像实时一样工作。

标签: pythonopencvcython

解决方案


使用 Mjpeg 作为编解码器并降低视频流源的 fps(每秒帧数)。

由于 mjpeg 与 H.264 相比压缩较少,因此带宽使用率会更高,但您的 cpu 使用率会更少。


推荐阅读