save something

This commit is contained in:
Evgeny Sorokin 2024-01-13 00:54:32 +00:00
parent d3a295872c
commit 57955b5964
5 changed files with 58 additions and 41 deletions

View File

@ -48,7 +48,8 @@ async def run_ffmpeg(cam: int, channel: int):
else:
debug_args = ['-nostats', '-loglevel', 'error']
protocol = 'tcp' if ipcam_config.should_use_tcp_for_rtsp(cam) else 'udp'
# protocol = 'tcp' if ipcam_config.should_use_tcp_for_rtsp(cam) else 'udp'
protocol = 'tcp'
user, pw = ipcam_config.get_rtsp_creds()
ip = ipcam_config.get_camera_ip(cam)
path = ipcam_config.get_camera_type(cam).get_channel_url(channel)

View File

@ -23,17 +23,13 @@ class IpcamConfig(ConfigUnit):
@classmethod
def schema(cls) -> Optional[dict]:
return {
'cams': {
'cameras': {
'type': 'dict',
'keysrules': {'type': ['string', 'integer']},
'valuesrules': {
'type': 'dict',
'schema': {
'type': {'type': 'string', 'allowed': [t.value for t in CameraType], 'required': True},
'codec': {'type': 'string', 'allowed': [t.value for t in VideoCodecType], 'required': True},
'container': {'type': 'string', 'allowed': [t.value for t in VideoContainerType], 'required': True},
'server': {'type': 'string', 'allowed': list(_lbc.get().keys()), 'required': True},
'disk': {'type': 'integer', 'required': True},
'motion': {
'type': 'dict',
'schema': {
@ -44,10 +40,18 @@ class IpcamConfig(ConfigUnit):
}
}
},
'rtsp_tcp': {'type': 'boolean'}
}
}
},
'areas': {
'type': 'dict',
'keysrules': {'type': 'string'},
'valuesrules': {
'type': 'list',
'schema': {'type': ['string', 'integer']} # same type as for 'cameras' keysrules
}
},
'camera_ip_template': {'type': 'string', 'required': True},
'motion_padding': {'type': 'integer', 'required': True},
'motion_telegram': {'type': 'boolean', 'required': True},
'fix_interval': {'type': 'integer', 'required': True},
@ -94,6 +98,7 @@ class IpcamConfig(ConfigUnit):
}
}
# FIXME
def get_all_cam_names(self,
filter_by_server: Optional[str] = None,
filter_by_disk: Optional[int] = None) -> list[int]:
@ -106,25 +111,22 @@ class IpcamConfig(ConfigUnit):
cams.append(int(cam))
return cams
def get_all_cam_names_for_this_server(self,
filter_by_disk: Optional[int] = None):
return self.get_all_cam_names(filter_by_server=socket.gethostname(),
filter_by_disk=filter_by_disk)
# def get_all_cam_names_for_this_server(self,
# filter_by_disk: Optional[int] = None):
# return self.get_all_cam_names(filter_by_server=socket.gethostname(),
# filter_by_disk=filter_by_disk)
def get_cam_server_and_disk(self, cam: int) -> tuple[str, int]:
return self['cams'][cam]['server'], self['cams'][cam]['disk']
# def get_cam_server_and_disk(self, cam: int) -> tuple[str, int]:
# return self['cams'][cam]['server'], self['cams'][cam]['disk']
def get_camera_container(self, cam: int) -> VideoContainerType:
return VideoContainerType(self['cams'][cam]['container'])
def get_camera_container(self, camera: int) -> VideoContainerType:
return self.get_camera_type(camera).get_container()
def get_camera_type(self, cam: int) -> CameraType:
return CameraType(self['cams'][cam]['type'])
def get_camera_type(self, camera: int) -> CameraType:
return CameraType(self['cams'][camera]['type'])
def get_rtsp_creds(self) -> tuple[str, str]:
return self['rtsp_creds']['login'], self['rtsp_creds']['password']
def should_use_tcp_for_rtsp(self, cam: int) -> bool:
return 'rtsp_tcp' in self['cams'][cam] and self['cams'][cam]['rtsp_tcp']
def get_camera_ip(self, camera: int) -> str:
return f'192.168.5.{camera}'
return self['camera_ip_template'] % (str(camera),)

View File

@ -1,25 +1,6 @@
from enum import Enum
class CameraType(Enum):
ESP32 = 'esp32'
ALIEXPRESS_NONAME = 'ali'
HIKVISION = 'hik'
def get_channel_url(self, channel: int) -> str:
if channel not in (1, 2):
raise ValueError(f'channel {channel} is invalid')
if channel == 1:
return ''
elif channel == 2:
if self.value == CameraType.HIKVISION:
return '/Streaming/Channels/2'
elif self.value == CameraType.ALIEXPRESS_NONAME:
return '/?stream=1.sdp'
else:
raise ValueError(f'unsupported camera type {self.value}')
class VideoContainerType(Enum):
MP4 = 'mp4'
MOV = 'mov'
@ -30,6 +11,37 @@ class VideoCodecType(Enum):
H265 = 'h265'
class CameraType(Enum):
ESP32 = 'esp32'
ALIEXPRESS_NONAME = 'ali'
HIKVISION_264 = 'hik_264'
HIKVISION_265 = 'hik_265'
def get_channel_url(self, channel: int) -> str:
if channel not in (1, 2):
raise ValueError(f'channel {channel} is invalid')
if channel == 1:
return ''
elif channel == 2:
if self.value in (CameraType.HIKVISION_264, CameraType.HIKVISION_265):
return '/Streaming/Channels/2'
elif self.value == CameraType.ALIEXPRESS_NONAME:
return '/?stream=1.sdp'
else:
raise ValueError(f'unsupported camera type {self.value}')
def get_codec(self, channel: int) -> VideoCodecType:
if channel == 1:
return VideoCodecType.H264 if self.value == CameraType.HIKVISION_264 else VideoCodecType.H265
elif channel == 2:
return VideoCodecType.H265 if self.value == CameraType.ALIEXPRESS_NONAME else VideoCodecType.H264
else:
raise ValueError(f'unexpected channel {channel}')
def get_container(self) -> VideoContainerType:
return VideoContainerType.MP4 if self.get_codec(1) == VideoCodecType.H264 else VideoContainerType.MOV
class TimeFilterType(Enum):
FIX = 'fix'
MOTION = 'motion'

View File

@ -6,7 +6,7 @@ Werkzeug==2.3.6
uwsgi~=2.0.20
python-telegram-bot==20.3
requests==2.31.0
aiohttp~=3.8.1
aiohttp~=3.9.1
pytz==2023.3
PyYAML~=6.0
apscheduler==3.10.1

2
tasks/df_h.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/sh
df -h