camera.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. """
  2. 摄像头配置
  3. """
  4. import platform
  5. import os
  6. LOG_CONFIG = {
  7. 'level': 'INFO',
  8. 'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  9. 'file': None,
  10. 'max_bytes': 10 * 1024 * 1024,
  11. 'backup_count': 5,
  12. 'retention_days': 7,
  13. }
  14. # ============================================================
  15. # 多组摄像头配置
  16. # 使用方法:启用需要的组(enabled=True),配置对应的IP地址
  17. # ============================================================
  18. # 摄像头组配置(devices.md)
  19. CAMERA_GROUPS = [
  20. {
  21. 'group_id': 'group_test',
  22. 'name': '测试环境',
  23. 'enabled': True,
  24. 'panorama': {
  25. 'ip': '192.168.8.2',
  26. 'port': 37777,
  27. 'rtsp_port': 554,
  28. 'username': 'admin',
  29. 'password': 'QAZwsx12',
  30. 'channel': 1,
  31. 'brand': 'hikvision',
  32. 'use_sdk': False,
  33. 'resolution': (2560, 1440),
  34. 'rtsp_url': 'rtsp://admin:QAZwsx12@192.168.8.2:554/Streaming/Channels/101',
  35. },
  36. 'ptz': {
  37. 'ip': '192.168.8.5',
  38. 'port': 37777,
  39. 'rtsp_port': 554,
  40. 'username': 'admin',
  41. 'password': 'Aa1234567',
  42. 'channel': 1,
  43. 'brand': 'dahua',
  44. 'subtype': 1,
  45. 'resolution': (3840, 2160),
  46. 'rtsp_url': 'rtsp://admin:Aa1234567@192.168.8.5:554/cam/realmonitor?channel=1&subtype=1',
  47. 'pan_flip': True,
  48. 'ceiling_mount': True,
  49. },
  50. },
  51. {
  52. 'group_id': 'group_prod',
  53. 'name': '正式环境',
  54. 'enabled': True,
  55. 'panorama': {
  56. 'ip': '192.168.20.196',
  57. 'port': 37777,
  58. 'rtsp_port': 554,
  59. 'username': 'admin',
  60. 'password': 'Aa1234567',
  61. 'channel': 1,
  62. 'brand': 'dahua',
  63. 'use_sdk': False,
  64. 'resolution': (3840, 1080),
  65. 'rtsp_url': 'rtsp://admin:Aa1234567@192.168.20.196:554/cam/realmonitor?channel=1&subtype=0',
  66. },
  67. 'ptz': {
  68. 'ip': '192.168.20.197',
  69. 'port': 37777,
  70. 'rtsp_port': 554,
  71. 'username': 'admin',
  72. 'password': 'Aa1234567',
  73. 'channel': 1,
  74. 'brand': 'dahua',
  75. 'subtype': 0,
  76. 'resolution': (3840, 2160),
  77. 'rtsp_url': 'rtsp://admin:Aa1234567@192.168.20.197:554/cam/realmonitor?channel=1&subtype=0',
  78. 'pan_flip': False,
  79. 'ceiling_mount': True,
  80. },
  81. },
  82. ]
  83. def get_enabled_groups() -> list:
  84. """获取所有启用的摄像头组配置"""
  85. return [g for g in CAMERA_GROUPS if g.get('enabled', False)]
  86. def parse_resolution(resolution) -> tuple:
  87. if resolution is None:
  88. return 1920, 1080
  89. if isinstance(resolution, (tuple, list)) and len(resolution) == 2:
  90. return int(resolution[0]), int(resolution[1])
  91. if isinstance(resolution, str):
  92. for sep in ['x', 'X', '*']:
  93. if sep in resolution:
  94. parts = resolution.split(sep)
  95. if len(parts) == 2:
  96. return int(parts[0]), int(parts[1])
  97. return 1920, 1080