144 lines
3.9 KiB
Python
144 lines
3.9 KiB
Python
"""
|
|
快速 RTSP 帧率检测工具
|
|
|
|
用法:
|
|
python quick_fps_check.py
|
|
然后输入 RTSP 地址
|
|
"""
|
|
|
|
import cv2
|
|
import time
|
|
import sys
|
|
|
|
|
|
def quick_fps_check(rtsp_url: str, duration: int = 5) -> dict:
|
|
"""快速检测 RTSP 流帧率"""
|
|
print(f"🔗 连接: {rtsp_url}")
|
|
|
|
# 连接视频流
|
|
cap = cv2.VideoCapture(rtsp_url)
|
|
cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
|
|
|
|
if not cap.isOpened():
|
|
return {"error": "无法连接到视频流"}
|
|
|
|
# 获取基本信息
|
|
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
|
declared_fps = cap.get(cv2.CAP_PROP_FPS)
|
|
|
|
print(f"📺 分辨率: {width}x{height}")
|
|
if declared_fps > 0:
|
|
print(f"📋 声明帧率: {declared_fps:.1f} FPS")
|
|
|
|
# 检测实际帧率
|
|
print(f"⏱️ 检测实际帧率 ({duration}秒)...")
|
|
|
|
frame_count = 0
|
|
start_time = time.time()
|
|
|
|
try:
|
|
while True:
|
|
ret, frame = cap.read()
|
|
if not ret:
|
|
break
|
|
|
|
frame_count += 1
|
|
elapsed = time.time() - start_time
|
|
|
|
# 显示进度
|
|
if frame_count % 10 == 0:
|
|
current_fps = frame_count / elapsed if elapsed > 0 else 0
|
|
print(f"\r📊 帧数: {frame_count}, 当前FPS: {current_fps:.1f}", end="", flush=True)
|
|
|
|
if elapsed >= duration:
|
|
break
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n⏹️ 检测中断")
|
|
|
|
finally:
|
|
cap.release()
|
|
|
|
total_time = time.time() - start_time
|
|
actual_fps = frame_count / total_time if total_time > 0 else 0
|
|
|
|
return {
|
|
"width": width,
|
|
"height": height,
|
|
"declared_fps": declared_fps,
|
|
"actual_fps": actual_fps,
|
|
"frame_count": frame_count,
|
|
"duration": total_time
|
|
}
|
|
|
|
|
|
def main():
|
|
print("🎥 快速 RTSP 帧率检测工具")
|
|
print("="*50)
|
|
|
|
# 获取 RTSP 地址
|
|
if len(sys.argv) > 1:
|
|
rtsp_url = sys.argv[1]
|
|
else:
|
|
print("请输入 RTSP 流地址:")
|
|
print("示例: rtsp://192.168.1.100:554/stream1")
|
|
print("示例: rtsp://admin:password@192.168.1.100:554/stream1")
|
|
rtsp_url = input("RTSP URL: ").strip()
|
|
|
|
if not rtsp_url:
|
|
print("❌ 未输入 RTSP 地址")
|
|
return
|
|
|
|
# 检测帧率
|
|
result = quick_fps_check(rtsp_url)
|
|
|
|
print(f"\n" + "="*50)
|
|
print("📊 检测结果")
|
|
print("="*50)
|
|
|
|
if "error" in result:
|
|
print(f"❌ {result['error']}")
|
|
return
|
|
|
|
print(f"📺 分辨率: {result['width']}x{result['height']}")
|
|
|
|
if result['declared_fps'] > 0:
|
|
print(f"📋 声明帧率: {result['declared_fps']:.1f} FPS")
|
|
else:
|
|
print(f"📋 声明帧率: 未知")
|
|
|
|
print(f"📊 实际帧率: {result['actual_fps']:.2f} FPS")
|
|
print(f"🎞️ 检测帧数: {result['frame_count']} 帧")
|
|
print(f"⏱️ 检测时长: {result['duration']:.2f} 秒")
|
|
|
|
# 帧率评估
|
|
fps = result['actual_fps']
|
|
if fps >= 25:
|
|
quality = "优秀 ✅ (适合实时监控)"
|
|
elif fps >= 15:
|
|
quality = "良好 🟡 (适合一般监控)"
|
|
elif fps >= 10:
|
|
quality = "一般 🟠 (适合低要求场景)"
|
|
elif fps >= 5:
|
|
quality = "较低 ❌ (仅适合静态场景)"
|
|
else:
|
|
quality = "很低 ❌ (不适合监控)"
|
|
|
|
print(f"🎯 帧率评估: {quality}")
|
|
|
|
# 与声明帧率对比
|
|
if result['declared_fps'] > 0:
|
|
diff = abs(result['actual_fps'] - result['declared_fps'])
|
|
if diff <= 2:
|
|
accuracy = "准确 ✅"
|
|
elif diff <= 5:
|
|
accuracy = "基本准确 🟡"
|
|
else:
|
|
accuracy = "差异较大 ❌"
|
|
|
|
print(f"📋 声明准确性: {accuracy} (差异: {diff:.1f} FPS)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |