python - 如何以低 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) 但它延迟了视频馈送处理,所以对我来说不会像实时一样工作。
解决方案
使用 Mjpeg 作为编解码器并降低视频流源的 fps(每秒帧数)。
由于 mjpeg 与 H.264 相比压缩较少,因此带宽使用率会更高,但您的 cpu 使用率会更少。
推荐阅读
- python - 未捕获 asyncio.CancelledError
- c# - OxyPlot 触发 LineSeries 颜色变化通知
- python - MQTT 和 Python - 继续发送消息
- javascript - 在 Angular 6 中找不到名称
- python - 如何从 Azure Databricks Spark 中的 DataFrame 获取特定的行和列
- javascript - 更改文本区域字体系列的功能(使用选项选择)
- javascript - CSS Floating ScrollTop按钮在iframe顶部不可点击
- shopware - 如何移动所有子类别 (ShopWare 5.4.6)
- http - 关于 shouldRedirectRLocked 方法的困惑(go1.11 src/net/http/server.go:2259)
- python - 重塑时出错