Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
I
ils-common-video
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
提交
议题看板
打开侧边栏
OpsTeam
ils-common-video
Commits
502889c5
提交
502889c5
authored
5月 06, 2021
作者:
zw.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 对接api服务
上级
dec1c218
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
72 行增加
和
17 行删除
+72
-17
recorder.py
hikvision_isc_client/recorder.py
+13
-13
api_helper.py
hikvision_isc_client/utils/api_helper.py
+55
-0
isc_client.py
hikvision_isc_client/utils/isc_client.py
+0
-0
test_devices.py
tests/test_devices.py
+1
-1
test_playback.py
tests/test_playback.py
+1
-1
test_preview.py
tests/test_preview.py
+1
-1
test_sub.py
tests/test_sub.py
+1
-1
没有找到文件。
hikvision_isc_client/recorder.py
浏览文件 @
502889c5
...
@@ -12,7 +12,7 @@ from intelab_python_sdk.logger import log_init, log
...
@@ -12,7 +12,7 @@ from intelab_python_sdk.logger import log_init, log
from
intelab_python_sdk.ffmpeg.ffmpeg_concat
import
concat
from
intelab_python_sdk.ffmpeg.ffmpeg_concat
import
concat
from
hikvision_isc_client.db
import
rabbitmq_connect
from
hikvision_isc_client.db
import
rabbitmq_connect
from
hikvision_isc_client.
client
import
HikVisionClient
from
hikvision_isc_client.
utils.api_helper
import
IntelabApiHelper
from
hikvision_isc_client.utils
import
aliyun_oss
from
hikvision_isc_client.utils
import
aliyun_oss
from
hikvision_isc_client.utils.record_utils
import
record_thread
,
get_video_duration
,
time_to_seconds
from
hikvision_isc_client.utils.record_utils
import
record_thread
,
get_video_duration
,
time_to_seconds
from
hikvision_isc_client.db.mysql
import
insert_video_info
from
hikvision_isc_client.db.mysql
import
insert_video_info
...
@@ -21,9 +21,7 @@ tz = pytz.timezone('Asia/Shanghai')
...
@@ -21,9 +21,7 @@ tz = pytz.timezone('Asia/Shanghai')
video_path
=
'/data/videos/isc-record'
video_path
=
'/data/videos/isc-record'
os
.
makedirs
(
video_path
,
exist_ok
=
True
)
os
.
makedirs
(
video_path
,
exist_ok
=
True
)
config
=
dynaconf
.
settings
.
get
(
'ISC'
)
api_helper
=
IntelabApiHelper
()
client
=
HikVisionClient
(
config
.
get
(
'KEY'
),
config
.
get
(
'SECRET'
),
config
.
get
(
'HOST'
),
config
.
get
(
'PORT'
))
class
StreamRecorder
:
class
StreamRecorder
:
...
@@ -54,7 +52,11 @@ class StreamRecorder:
...
@@ -54,7 +52,11 @@ class StreamRecorder:
thread_id
=
threading
.
get_ident
()
thread_id
=
threading
.
get_ident
()
log
.
info
(
'Thread id:
%
s Delivery tag:
%
s Message body:
%
s'
,
thread_id
,
log
.
info
(
'Thread id:
%
s Delivery tag:
%
s Message body:
%
s'
,
thread_id
,
delivery_tag
,
body
)
delivery_tag
,
body
)
try
:
# TODO 异常报错时不需要ack掉消息
self
.
process_message
(
body
)
self
.
process_message
(
body
)
except
Exception
as
e
:
log
.
exception
(
e
)
cb
=
functools
.
partial
(
ack_message
,
ch
,
delivery_tag
)
cb
=
functools
.
partial
(
ack_message
,
ch
,
delivery_tag
)
conn
.
add_callback_threadsafe
(
cb
)
conn
.
add_callback_threadsafe
(
cb
)
...
@@ -92,10 +94,9 @@ class StreamRecorder:
...
@@ -92,10 +94,9 @@ class StreamRecorder:
def
process_message
(
self
,
body
):
def
process_message
(
self
,
body
):
t1
=
time
.
time
()
t1
=
time
.
time
()
record_result
=
self
.
recorder
(
record_result
=
self
.
recorder
(
body
[
'camera_
index
'
],
body
[
'camera_
code
'
],
datetime
.
strptime
(
body
[
'start_time'
],
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S'
)
.
astimezone
(
tz
),
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
),
datetime
.
strptime
(
body
[
'end_time'
],
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S'
)
.
astimezone
(
tz
),
body
[
'camera_code'
]
)
)
t2
=
time
.
time
()
t2
=
time
.
time
()
...
@@ -119,17 +120,16 @@ class StreamRecorder:
...
@@ -119,17 +120,16 @@ class StreamRecorder:
return
True
return
True
@staticmethod
@staticmethod
def
recorder
(
camera_
index
,
start_time
,
end_time
,
camera_cod
e
):
def
recorder
(
camera_
code
,
start_time
,
end_tim
e
):
"""
"""
:param camera_
index:
:param camera_
code: 摄像头序列号
:param start_time: 开始时间,上海时区
:param start_time: 开始时间,上海时区
:param end_time: 结束时间,上海时区
:param end_time: 结束时间,上海时区
:param camera_code: 摄像头序列号
"""
"""
playback_urls
=
client
.
get_cameras_playback_urls
(
playback_urls
=
api_helper
.
get_cameras_playback_urls
(
camera_
index
,
camera_
code
,
HikVisionClient
.
iso_format
(
start_time
),
IntelabApiHelper
.
iso_format
(
start_time
),
HikVisionClient
.
iso_format
(
end_time
)
IntelabApiHelper
.
iso_format
(
end_time
)
)
)
log
.
info
(
'playback:
%
s'
,
playback_urls
)
log
.
info
(
'playback:
%
s'
,
playback_urls
)
file_name
=
os
.
path
.
join
(
video_path
,
'ISC_{}_{}_{}.mp4'
.
format
(
file_name
=
os
.
path
.
join
(
video_path
,
'ISC_{}_{}_{}.mp4'
.
format
(
...
...
hikvision_isc_client/utils/api_helper.py
0 → 100644
浏览文件 @
502889c5
import
json
import
requests
import
dynaconf
import
dateutil.parser
from
datetime
import
datetime
,
timedelta
class
IntelabApiHelper
:
def
__init__
(
self
):
config
=
dynaconf
.
settings
.
get
(
'COMMON'
)
self
.
host
=
config
.
get
(
'HOST'
)
@staticmethod
def
iso_format
(
t
):
return
'{}+08:00'
.
format
(
t
.
strftime
(
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.
%
f'
)[:
-
3
])
def
get_cameras_playback_urls
(
self
,
camera_code
,
start_time
,
end_time
,
protocol
=
'rtmp'
):
streamform
=
'ps'
if
protocol
==
'rtmp'
else
'rtp'
params
=
{
'beginTime'
:
start_time
,
'endTime'
:
end_time
,
'protocol'
:
protocol
,
'streamform'
:
streamform
}
uri
=
'/python/api/v1/secure/camera/playback/urls/{}'
.
format
(
camera_code
)
expired_time
=
datetime
.
now
()
+
timedelta
(
minutes
=
5
)
response
=
requests
.
get
(
self
.
host
+
uri
,
params
=
params
,
timeout
=
30
)
response
.
raise_for_status
()
res_json
=
response
.
json
()
.
get
(
'data'
)
results
=
[]
for
f
in
res_json
.
get
(
'list'
)
or
[]:
start_time
=
dateutil
.
parser
.
parse
(
f
[
'beginTime'
])
end_time
=
dateutil
.
parser
.
parse
(
f
[
'endTime'
])
results
.
append
({
'start_time'
:
start_time
,
'end_time'
:
end_time
,
'expired_time'
:
expired_time
,
'stream_url'
:
{
'url'
:
res_json
.
get
(
'url'
),
'extra_args'
:
'playBackMode=1'
,
'protocol'
:
protocol
}
})
return
results
if
__name__
==
'__main__'
:
api_helper
=
IntelabApiHelper
()
print
(
api_helper
.
get_cameras_playback_urls
(
'D86639983'
,
'2021-05-06T10:14:35.000+08:00'
,
'2021-05-06T10:15:41.000+08:00'
))
hikvision_isc_client/client.py
→
hikvision_isc_client/
utils/isc_
client.py
浏览文件 @
502889c5
File moved
tests/test_devices.py
浏览文件 @
502889c5
from
dynaconf
import
settings
from
dynaconf
import
settings
from
hikvision_isc_client.client
import
HikVisionClient
from
hikvision_isc_client.
utils.isc_
client
import
HikVisionClient
config
=
settings
.
get
(
'ISC'
)
config
=
settings
.
get
(
'ISC'
)
client
=
HikVisionClient
(
config
.
get
(
'KEY'
),
config
.
get
(
'SECRET'
),
client
=
HikVisionClient
(
config
.
get
(
'KEY'
),
config
.
get
(
'SECRET'
),
...
...
tests/test_playback.py
浏览文件 @
502889c5
...
@@ -4,7 +4,7 @@ from datetime import datetime
...
@@ -4,7 +4,7 @@ from datetime import datetime
from
intelab_python_sdk.logger
import
log_init
from
intelab_python_sdk.logger
import
log_init
from
dynaconf
import
settings
from
dynaconf
import
settings
from
hikvision_isc_client.client
import
HikVisionClient
from
hikvision_isc_client.
utils.isc_
client
import
HikVisionClient
from
hikvision_isc_client.recorder
import
StreamRecorder
from
hikvision_isc_client.recorder
import
StreamRecorder
...
...
tests/test_preview.py
浏览文件 @
502889c5
from
dynaconf
import
settings
from
dynaconf
import
settings
from
hikvision_isc_client.client
import
HikVisionClient
from
hikvision_isc_client.
utils.isc_
client
import
HikVisionClient
config
=
settings
.
get
(
'ISC'
)
config
=
settings
.
get
(
'ISC'
)
client
=
HikVisionClient
(
config
.
get
(
'KEY'
),
config
.
get
(
'SECRET'
),
client
=
HikVisionClient
(
config
.
get
(
'KEY'
),
config
.
get
(
'SECRET'
),
...
...
tests/test_sub.py
浏览文件 @
502889c5
from
dynaconf
import
settings
from
dynaconf
import
settings
from
hikvision_isc_client.client
import
HikVisionClient
from
hikvision_isc_client.
utils.isc_
client
import
HikVisionClient
config
=
settings
.
get
(
'ISC'
)
config
=
settings
.
get
(
'ISC'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论