Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
I
ils-common-video
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
提交
议题看板
打开侧边栏
OpsTeam
ils-common-video
Commits
97d735cd
提交
97d735cd
authored
5月 04, 2021
作者:
zw.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 视频信息插入mysql
上级
d4a61efc
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
67 行增加
和
43 行删除
+67
-43
README.md
README.md
+2
-0
mysql.py
hikvision_isc_client/db/mysql.py
+28
-31
recorder.py
hikvision_isc_client/recorder.py
+36
-11
setup.py
setup.py
+1
-1
没有找到文件。
README.md
浏览文件 @
97d735cd
...
...
@@ -2,3 +2,5 @@
This is the Python SDK to interact with Hikvision iSC platform using Hikvision's open API.
## CONFIG
hikvision_isc_client/db/mysql.py
浏览文件 @
97d735cd
...
...
@@ -76,37 +76,34 @@ def query(cursor_dict=False):
return
in_func
@query
(
cursor_dict
=
True
)
def
get_camera_sn
(
cursor
,
conn
):
sql
=
'''
select
device_number camera_sn,
biz_type,
name camera_name
from camera.video_config
'''
# where device_number = 'E57379052'
cursor
.
execute
(
sql
)
return
cursor
.
fetchall
()
@query
(
cursor_dict
=
True
)
def
get_camera_video_url
(
cursor
,
conn
,
table
,
camera_sn
,
date
):
sql
=
'''
select video_url, id video_id, status, start_date, end_date, file_name
from {}
where date =
%
s and device_serial =
%
s
'''
.
format
(
table
)
cursor
.
execute
(
sql
,
[
date
,
camera_sn
])
return
cursor
.
fetchall
()
@query
()
def
set_video_data_status
(
cursor
,
conn
,
table
,
video_id
):
def
insert_video_info
(
cursor
,
conn
,
device_code
,
file_name
,
start_time
,
end_time
,
recovered_time
,
date
,
video_url
,
video_resolution
,
status
=
0
):
sql
=
'''
update {}
set status = 0
where id =
%
s
'''
.
format
(
table
)
cursor
.
execute
(
sql
,
[
video_id
])
insert video_data_motion_test (
device_code, file_name, start_date, end_date,
recovered_time, date,
video_url, video_resolution,
biz_type, service_type,
expired_time, status, update_time)
value (
%(device_code)
s,
%(file_name)
s,
%(start_date)
s,
%(end_date)
s,
%(recovered_time)
s,
%(date)
s,
%(video_url)
s,
%(video_resolution)
s,
1, 1,
date_add(now(),interval 31 day),
%(status)
s, now()
)
'''
cursor
.
execute
(
sql
,
{
'device_code'
:
device_code
,
'file_name'
:
file_name
,
'start_date'
:
start_time
,
'end_date'
:
end_time
,
'video_url'
:
video_url
,
'video_resolution'
:
video_resolution
,
'recovered_time'
:
recovered_time
,
'date'
:
date
,
'status'
:
status
})
video_id
=
cursor
.
lastrowid
conn
.
commit
()
return
video_id
hikvision_isc_client/recorder.py
浏览文件 @
97d735cd
...
...
@@ -14,6 +14,7 @@ from hikvision_isc_client.db import rabbitmq_connect
from
hikvision_isc_client.client
import
HikVisionClient
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.db.mysql
import
insert_video_info
tz
=
pytz
.
timezone
(
'Asia/Shanghai'
)
...
...
@@ -60,18 +61,20 @@ class StreamRecorder:
(
conn
,
thrds
)
=
args
body
=
json
.
loads
(
body
)
delivery_tag
=
method_frame
.
delivery_tag
t
=
threading
.
Thread
(
target
=
do_work
,
args
=
(
conn
,
ch
,
delivery_tag
,
body
))
t
=
threading
.
Thread
(
target
=
do_work
,
args
=
(
conn
,
ch
,
delivery_tag
,
body
))
t
.
start
()
thrds
.
append
(
t
)
threads
=
[]
on_message_callback
=
functools
.
partial
(
on_message
,
args
=
(
self
.
connection
,
threads
))
on_message_callback
=
functools
.
partial
(
on_message
,
args
=
(
self
.
connection
,
threads
))
self
.
channel
.
basic_qos
(
prefetch_count
=
1
)
self
.
channel
.
basic_consume
(
on_message_callback
=
on_message_callback
,
queue
=
self
.
queue_name
)
log
.
info
(
'
[*] Waiting for messages. To exit press CTRL+C'
)
log
.
info
(
'[*] Waiting for messages. To exit press CTRL+C'
)
try
:
self
.
channel
.
start_consuming
()
except
KeyboardInterrupt
:
...
...
@@ -86,16 +89,26 @@ class StreamRecorder:
self
.
connection
.
close
()
def
process_message
(
self
,
body
):
file_name
=
self
.
recorder
(
record_result
=
self
.
recorder
(
body
[
'camera_index'
],
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
)
video_info
,
error_log
=
get_video_duration
(
record_result
[
'file_name'
])
url
=
''
if
file_name
and
os
.
path
.
isfile
(
file_name
):
url
=
aliyun_oss
.
oss_upload_file
(
'isc_record/'
+
file_name
.
split
(
'/'
)[
-
1
],
file_name
)
log
.
info
(
'video_info:
%
s, url:
%
s'
,
video_info
,
url
)
file_name
=
record_result
[
'file_name'
]
.
split
(
'/'
)[
-
1
]
if
record_result
[
'file_name'
]
and
os
.
path
.
isfile
(
record_result
[
'file_name'
]):
url
=
aliyun_oss
.
oss_upload_file
(
'isc_record/'
+
file_name
,
record_result
[
'file_name'
])
os
.
remove
(
record_result
[
'file_name'
])
video_id
=
insert_video_info
(
body
[
'camera_code'
],
file_name
,
body
[
'start_time'
],
body
[
'end_time'
],
recovered_time
=
record_result
[
'recovered_time'
],
date
=
body
[
'start_time'
]
.
split
(
'T'
)[
0
]
.
replace
(
'-'
,
''
),
video_url
=
url
,
video_resolution
=
video_info
[
'resolution'
],
status
=
1
if
record_result
[
'is_completed'
]
else
2
)
log
.
info
(
'video_info:
%
s, url:
%
s, video_id:
%
s'
,
video_info
,
url
,
video_id
)
return
True
@staticmethod
...
...
@@ -111,14 +124,17 @@ class StreamRecorder:
playback_stream
=
playback_urls
[
0
]
else
:
return
part_num
=
1
part_num
=
retry_count
=
0
is_completed
=
False
part_files_set
=
set
()
file_name
=
os
.
path
.
join
(
video_path
,
'rtmp_{}_{}.mp4'
.
format
(
start_time
.
astimezone
(
pytz
.
utc
)
.
strftime
(
'
%
Y
%
m
%
dT
%
H
%
M
%
S'
),
end_time
.
astimezone
(
pytz
.
utc
)
.
strftime
(
'
%
Y
%
m
%
dT
%
H
%
M
%
S'
)
))
while
True
:
while
retry_count
<
6
:
# 重试六次
retry_count
+=
1
complete_duration
=
(
end_time
-
start_time
)
.
total_seconds
()
file_info
,
_
=
StreamRecorder
.
stream_record
(
...
...
@@ -139,16 +155,25 @@ class StreamRecorder:
start_time
=
new_start_time
part_num
+=
1
retry_count
=
0
else
:
part_files_set
.
add
(
file_info
[
'file_name'
])
is_completed
=
True
start_time
=
end_time
break
part_files
=
sorted
(
list
(
part_files_set
))
if
len
(
part_files
)
>
1
:
concat
(
part_files
,
file_name
,
removed
=
True
)
elif
len
(
part_files
)
==
1
:
shutil
.
move
(
part_files
[
0
],
file_name
)
log
.
info
(
'The download is complete, file
%
s'
,
file_name
)
return
file_name
return
{
'file_name'
:
file_name
,
'is_completed'
:
is_completed
,
'recovered_time'
:
start_time
,
'retry_count'
:
retry_count
}
@staticmethod
def
stream_record
(
stream
,
start_time
,
end_time
):
...
...
setup.py
浏览文件 @
97d735cd
...
...
@@ -5,7 +5,7 @@ with open('README.md', 'r') as fh:
setuptools
.
setup
(
name
=
'hikvision-isc-client'
,
version
=
'0.0.
1
'
,
version
=
'0.0.
2
'
,
author
=
''
,
author_email
=
''
,
description
=
'Client to interact with Hikvision iSC platform using open API'
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论