提交 d4a61efc authored 作者: zw.wang's avatar zw.wang

fix: 修复时区问题

上级 51a90c5b
......@@ -130,7 +130,7 @@ class HikVisionClient(object):
'expand': 'fileSize=1024',
'streamform': streamform
}
print('Body: %s', body)
print('requests body: {}'.format(body))
expired_time = datetime.now() + timedelta(minutes=5)
res = self._request(uri, body)
results = []
......
LAST_CHECK_TIME_KEY = 'isc:recorder:camera:{}'
LAST_CHECK_TIME_KEY = 'hk_isc:recorder:camera:{}'
import pytz
import json
import time
import dateutil.parser
from datetime import datetime, timedelta
from intelab_python_sdk.logger import log
from hikvision_isc_client.db import influxdb, rabbitmq_connect, redis_connect
from hikvision_isc_client.db import rabbitmq_connect, redis_connect
from hikvision_isc_client.const import LAST_CHECK_TIME_KEY
from hikvision_isc_client.pre_event import PreEvent
......@@ -49,29 +48,30 @@ class EventMergerJob:
pipe = redis_connect()
for camera in get_camera_info():
now_std = datetime.now(pytz.timezone('Asia/Shanghai'))
now = datetime.utcnow()
camera_code = camera['device_code']
last_check_time_key = LAST_CHECK_TIME_KEY.format(camera_code)
last_check_time = pipe.get(last_check_time_key)
if not last_check_time:
# 设备无上次事件,取最近的15分钟作为开始时间
last_check_time = now_std - timedelta(minutes=15)
last_check_time = now - timedelta(minutes=15)
else:
last_check_time = dateutil.parser.parse(
last_check_time).astimezone(tz)
last_check_time = datetime.strptime(last_check_time, '%Y-%m-%d %H:%M:%S')
# 调整最大事件长度为1天
if now_std - last_check_time > timedelta(days=1):
last_check_time = now_std - timedelta(days=1)
if now - last_check_time > timedelta(days=1):
last_check_time = now - timedelta(days=1)
res = pipe.set(last_check_time_key,
now_std.astimezone(pytz.utc).strftime('%Y-%m-%d %H:%M:%S'))
now.strftime('%Y-%m-%d %H:%M:%S'))
if not res:
continue
pre_event = PreEvent(last_check_time.strftime('%Y-%m-%d %H:%M:%S'),
now_std.strftime('%Y-%m-%d %H:%M:%S'))
alarm_list = pre_event.get_alarm_list(camera['index_code'])
log.info('time: {}-{}, alarm_list: {}'.format(last_check_time, now_std, len(alarm_list)))
pre_event = PreEvent(
last_check_time.strftime('%Y-%m-%d %H:%M:%S'),
now.strftime('%Y-%m-%d %H:%M:%S')
)
alarm_list = list(pre_event.get_alarm_list(camera['index_code']))
log.info('time: {}-{}, alarm_list: {}'.format(last_check_time, now, len(alarm_list)))
connection = None
# if len(alarm_list) > 0:
connection = rabbitmq_connect()
......@@ -79,8 +79,8 @@ class EventMergerJob:
channel.queue_declare(self.queue_name, durable=True)
# TODO 测试持续获取事件
events = [{'start_time': last_check_time, 'end_time': now_std}]
# events = PreEvent.merge_alarm_to_event(alarm_list)
# events = [{'start_time': last_check_time, 'end_time': now_std}]
events = PreEvent.merge_alarm_to_event(alarm_list)
for event in events:
body = {
......
......@@ -88,8 +88,9 @@ class StreamRecorder:
def process_message(self, body):
file_name = self.recorder(
body['camera_index'],
datetime.strptime(body['start_time'], '%Y-%m-%dT%H:%M:%S'),
datetime.strptime(body['end_time'], '%Y-%m-%dT%H:%M:%S'))
datetime.strptime(body['start_time'], '%Y-%m-%dT%H:%M:%S').astimezone(tz),
datetime.strptime(body['end_time'], '%Y-%m-%dT%H:%M:%S').astimezone(tz)
)
video_info = get_video_duration(file_name)
url = ''
if file_name and os.path.isfile(file_name):
......@@ -110,7 +111,6 @@ class StreamRecorder:
playback_stream = playback_urls[0]
else:
return
log.info(playback_stream)
part_num = 1
part_files_set = set()
file_name = os.path.join(video_path, 'rtmp_{}_{}.mp4'.format(
......@@ -163,6 +163,7 @@ class StreamRecorder:
end_time, stream['extra_args'])
file_name = os.path.join(
video_path, 'rtmp_{}_{}.mp4'.format(start_time, end_time))
log.info('stream_url: %s', stream_url)
record_thread(stream_url, file_name)
return get_video_duration(file_name)
......
......@@ -37,7 +37,10 @@ def record_thread(stream_url, out_file):
if 'DTS' in log_buffer:
# 屏蔽日志中'Non-monotonous DTS in output stream:' 的告警信息
log_buffer = ''
if log_buffer:
if log_buffer and 'error' in log_buffer:
log.error('ffmpeg-log:error: %s', log_buffer.strip())
elif log_buffer:
log.debug('ffmpeg-log: %s', log_buffer.strip())
log_buffer = stdout
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论