Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
I
ils-common-video
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
提交
议题看板
打开侧边栏
OpsTeam
ils-common-video
Commits
53d54e88
提交
53d54e88
authored
7月 01, 2021
作者:
zw.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [isc_client] 使用组件编码H264摄像头
上级
c0881c71
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
48 行增加
和
23 行删除
+48
-23
Dockerfile
Dockerfile
+2
-1
recorder.py
isc_video_record/recorder.py
+9
-4
isc_client.py
isc_video_record/utils/isc_client.py
+15
-9
record_utils.py
isc_video_record/utils/record_utils.py
+15
-3
setup.py
setup.py
+1
-1
test_playback.py
tests/test_playback.py
+6
-5
没有找到文件。
Dockerfile
浏览文件 @
53d54e88
...
@@ -5,7 +5,8 @@ ARG WORKNAME
...
@@ -5,7 +5,8 @@ ARG WORKNAME
ENV
LANG C.UTF-8
ENV
LANG C.UTF-8
WORKDIR
/root/isc-video-record
WORKDIR
/root/isc-video-record
RUN
pip
install
-U
pip intelab-python-sdk
RUN
pip
install
-U
pip
\
&&
pip
install
-U
intelab-python-sdk
-i
https://pypi.org/simple
RUN
pip
install
supervisor
\
RUN
pip
install
supervisor
\
&&
echo_supervisord_conf
>
/etc/supervisord.conf
\
&&
echo_supervisord_conf
>
/etc/supervisord.conf
\
...
...
isc_video_record/recorder.py
浏览文件 @
53d54e88
...
@@ -14,6 +14,7 @@ from intelab_python_sdk.ffmpeg.ffmpeg_concat import concat
...
@@ -14,6 +14,7 @@ from intelab_python_sdk.ffmpeg.ffmpeg_concat import concat
from
isc_video_record.db
import
rabbitmq_connect
,
redis_connect
,
influxdb
from
isc_video_record.db
import
rabbitmq_connect
,
redis_connect
,
influxdb
from
isc_video_record.const
import
PROCESSING_CAMERA_KEY
from
isc_video_record.const
import
PROCESSING_CAMERA_KEY
from
isc_video_record.utils.api_helper
import
IntelabApiHelper
,
PlaybackUrlException
from
isc_video_record.utils.api_helper
import
IntelabApiHelper
,
PlaybackUrlException
from
isc_video_record.utils.isc_client
import
HikVisionClient
from
isc_video_record.utils
import
aliyun_oss
from
isc_video_record.utils
import
aliyun_oss
from
isc_video_record.utils.record_utils
import
record_thread
,
get_video_duration
,
time_to_seconds
from
isc_video_record.utils.record_utils
import
record_thread
,
get_video_duration
,
time_to_seconds
from
isc_video_record.utils.alarm_utils
import
send_alarm_to_developer
from
isc_video_record.utils.alarm_utils
import
send_alarm_to_developer
...
@@ -23,7 +24,11 @@ tz = pytz.timezone('Asia/Shanghai')
...
@@ -23,7 +24,11 @@ tz = pytz.timezone('Asia/Shanghai')
video_path
=
'/tmp/videos/isc-record'
video_path
=
'/tmp/videos/isc-record'
os
.
makedirs
(
video_path
,
exist_ok
=
True
)
os
.
makedirs
(
video_path
,
exist_ok
=
True
)
api_helper
=
IntelabApiHelper
()
hk_config
=
dynaconf
.
settings
.
get
(
'ISC'
)
hik_client
=
HikVisionClient
(
str
(
hk_config
.
get
(
'KEY'
)),
hk_config
.
get
(
'SECRET'
),
hk_config
.
get
(
'HOST'
),
hk_config
.
get
(
'PORT'
))
# api_helper = IntelabApiHelper()
class
StreamRecorder
:
class
StreamRecorder
:
...
@@ -272,8 +277,8 @@ class ProcessMessage:
...
@@ -272,8 +277,8 @@ class ProcessMessage:
res
=
{
'file_name'
:
file_name
,
'is_completed'
:
False
,
'recovered_time'
:
start_time
}
res
=
{
'file_name'
:
file_name
,
'is_completed'
:
False
,
'recovered_time'
:
start_time
}
try
:
try
:
playback_urls
=
api_helper
.
get_cameras_playback_urls
(
playback_urls
=
hik_client
.
get_cameras_playback_urls
(
self
.
body
[
'camera_
code
'
],
self
.
body
[
'camera_
index
'
],
IntelabApiHelper
.
iso_format
(
start_time
),
IntelabApiHelper
.
iso_format
(
start_time
),
IntelabApiHelper
.
iso_format
(
end_time
)
IntelabApiHelper
.
iso_format
(
end_time
)
)
)
...
@@ -309,7 +314,7 @@ class ProcessMessage:
...
@@ -309,7 +314,7 @@ class ProcessMessage:
file_duration
=
time_to_seconds
(
file_info
[
'duration'
])
file_duration
=
time_to_seconds
(
file_info
[
'duration'
])
if
not
os
.
path
.
isfile
(
file_info
[
'file_name'
]):
if
not
os
.
path
.
isfile
(
file_info
[
'file_name'
]):
log
.
info
(
'当前录制无文件输出:
%
s, 重试计数:
%
s'
,
self
.
body
[
'camera_code'
],
retry_count
)
log
.
info
(
'当前录制无文件输出:
%
s, 重试计数:
%
s'
,
self
.
body
[
'camera_code'
],
retry_count
)
time
.
sleep
(
1
)
time
.
sleep
(
5
)
elif
file_duration
<
complete_duration
-
2
:
elif
file_duration
<
complete_duration
-
2
:
# 视频文件时长小于完整时长
# 视频文件时长小于完整时长
new_start_time
=
start_time
+
timedelta
(
seconds
=
file_duration
)
new_start_time
=
start_time
+
timedelta
(
seconds
=
file_duration
)
...
...
isc_video_record/utils/isc_client.py
浏览文件 @
53d54e88
...
@@ -128,18 +128,25 @@ class HikVisionClient(object):
...
@@ -128,18 +128,25 @@ class HikVisionClient(object):
'endTime'
:
end_time
,
'endTime'
:
end_time
,
'recordLocation'
:
1
,
'recordLocation'
:
1
,
'protocol'
:
protocol
,
'protocol'
:
protocol
,
'expand'
:
'
fileSize=102
4'
,
'expand'
:
'
transcode=1&fileSize=1024&videotype=h26
4'
,
'streamform'
:
streamform
,
'streamform'
:
streamform
,
}
}
log
.
info
(
'requests body: {}'
.
format
(
body
))
log
.
info
(
'requests body: {}'
.
format
(
body
))
expired_time
=
datetime
.
now
()
+
timedelta
(
minutes
=
5
)
expired_time
=
datetime
.
now
()
+
timedelta
(
minutes
=
5
)
res
=
self
.
_request
(
uri
,
body
)
res
=
self
.
_request
(
uri
,
body
)
results
=
[]
events
=
[]
for
f
in
res
.
get
(
'list'
)
or
[]:
for
pre_event
in
res
.
get
(
'list'
)
or
[]:
start_time
=
dateutil
.
parser
.
parse
(
f
[
'beginTime'
])
if
pre_event
.
get
(
'online'
,
1
)
==
'0'
:
end_time
=
dateutil
.
parser
.
parse
(
f
[
'endTime'
])
raise
PlaybackUrlException
({
'message'
:
'offline'
,
'code'
:
404
})
results
.
append
({
start_time
=
dateutil
.
parser
.
parse
(
pre_event
[
'beginTime'
])
end_time
=
dateutil
.
parser
.
parse
(
pre_event
[
'endTime'
])
if
len
(
events
)
>
0
\
and
start_time
-
events
[
-
1
][
'end_time'
]
<=
timedelta
(
seconds
=
2
)
\
and
events
[
-
1
][
'end_time'
]
-
events
[
-
1
][
'start_time'
]
<=
timedelta
(
hours
=
0.5
):
events
[
-
1
][
'end_time'
]
=
end_time
else
:
events
.
append
({
'start_time'
:
start_time
,
'start_time'
:
start_time
,
'end_time'
:
end_time
,
'end_time'
:
end_time
,
'expired_time'
:
expired_time
,
'expired_time'
:
expired_time
,
...
@@ -148,10 +155,9 @@ class HikVisionClient(object):
...
@@ -148,10 +155,9 @@ class HikVisionClient(object):
'extra_args'
:
'playBackMode=1'
,
'extra_args'
:
'playBackMode=1'
,
'protocol'
:
protocol
'protocol'
:
protocol
}
}
})
})
return
resul
ts
return
even
ts
def
event_subscription
(
self
,
callback
):
def
event_subscription
(
self
,
callback
):
""" 事件订阅接口
""" 事件订阅接口
...
...
isc_video_record/utils/record_utils.py
浏览文件 @
53d54e88
...
@@ -4,13 +4,25 @@ import subprocess
...
@@ -4,13 +4,25 @@ import subprocess
from
intelab_python_sdk.logger
import
log
from
intelab_python_sdk.logger
import
log
def
record_thread
(
stream_url
,
out_file
,
thread_name
=
'ffmpeg-log'
):
def
record_thread
(
stream_url
,
out_file
,
thread_name
=
'ffmpeg-log'
,
protocol
=
'rtmp'
):
if
protocol
==
'rtsp'
:
cmd
=
[
cmd
=
[
'ffmpeg'
,
'ffmpeg'
,
'-y'
,
'-y'
,
'-rw_timeout'
,
'20000000'
,
'-v'
,
'info'
,
'-v'
,
'info'
,
'-use_wallclock_as_timestamps'
,
'1'
,
'-rtsp_transport'
,
'tcp'
,
'-i'
,
stream_url
,
'-c'
,
'copy'
,
'-f'
,
'mp4'
,
out_file
]
else
:
cmd
=
[
'ffmpeg'
,
'-y'
,
'-v'
,
'info'
,
'-rw_timeout'
,
'20000000'
,
'-i'
,
stream_url
,
'-i'
,
stream_url
,
'-c'
,
'copy'
,
'-c'
,
'copy'
,
'-f'
,
'mp4'
,
'-f'
,
'mp4'
,
...
...
setup.py
浏览文件 @
53d54e88
...
@@ -24,7 +24,7 @@ requires = [
...
@@ -24,7 +24,7 @@ requires = [
setuptools
.
setup
(
setuptools
.
setup
(
name
=
'isc-video-record'
,
name
=
'isc-video-record'
,
version
=
'1.0.0b
9
'
,
version
=
'1.0.0b
11
'
,
description
=
'ISC motion detection playback video stream recording service.'
,
description
=
'ISC motion detection playback video stream recording service.'
,
long_description
=
long_description
,
long_description
=
long_description
,
long_description_content_type
=
'text/markdown'
,
long_description_content_type
=
'text/markdown'
,
...
...
tests/test_playback.py
浏览文件 @
53d54e88
...
@@ -23,16 +23,17 @@ client = HikVisionClient(config.get('KEY'), config.get('SECRET'),
...
@@ -23,16 +23,17 @@ client = HikVisionClient(config.get('KEY'), config.get('SECRET'),
def
main
():
def
main
():
start_time
=
datetime
(
2021
,
6
,
23
,
12
,
15
,
29
)
.
astimezone
(
tz
)
start_time
=
datetime
(
2021
,
6
,
30
,
18
,
58
,
29
)
.
astimezone
(
tz
)
# start_time = datetime(2021, 5, 28, 9, 10, 59).astimezone(tz)
# start_time = datetime(2021, 5, 28, 9, 10, 59).astimezone(tz)
end_time
=
datetime
(
2021
,
6
,
23
,
12
,
17
,
32
)
.
astimezone
(
tz
)
end_time
=
datetime
(
2021
,
6
,
30
,
18
,
59
,
0
)
.
astimezone
(
tz
)
camera_index
=
'
1f1878fd4e8b4e60b2adb1c0290458e8
'
camera_index
=
'
be03d4d8b12344a9adc92bfbf11fef53
'
results
=
[]
results
=
[]
try
:
try
:
res
=
client
.
get_cameras_playback_urls
(
res
=
client
.
get_cameras_playback_urls
(
camera_index
,
camera_index
,
client
.
iso_format
(
start_time
),
client
.
iso_format
(
end_time
)
client
.
iso_format
(
start_time
),
client
.
iso_format
(
end_time
),
protocol
=
'rtsp'
)
)
results
.
extend
(
res
)
results
.
extend
(
res
)
except
PlaybackUrlException
as
e
:
except
PlaybackUrlException
as
e
:
...
@@ -75,7 +76,7 @@ def stream_record(stream, start_time, end_time):
...
@@ -75,7 +76,7 @@ def stream_record(stream, start_time, end_time):
video_path
,
'rtmp_{}_{}_{}.mp4'
.
format
(
'y'
,
start_time
,
end_time
))
video_path
,
'rtmp_{}_{}_{}.mp4'
.
format
(
'y'
,
start_time
,
end_time
))
# TODO 多进程处理
# TODO 多进程处理
print
(
stream_url
,
start_time
,
end_time
)
print
(
stream_url
,
start_time
,
end_time
)
record_thread
(
stream_url
,
file_name
,
thread_name
=
'y'
)
record_thread
(
stream_url
,
file_name
,
thread_name
=
'y'
,
protocol
=
stream
[
'protocol'
]
)
return
get_video_duration
(
file_name
)
return
get_video_duration
(
file_name
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论