Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
20f473e2
提交
20f473e2
authored
8月 17, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
bf64a600
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
99 行删除
+51
-99
Makefile
opencv-motion-detect/Makefile
+1
-1
evmlmotion.cpp
opencv-motion-detect/evmlmotion.cpp
+50
-98
没有找到文件。
opencv-motion-detect/Makefile
浏览文件 @
20f473e2
...
@@ -34,7 +34,7 @@ evslicer: evslicer.cpp inc/common.hpp inc/tinythread.hpp database.cpp sqlite3.o
...
@@ -34,7 +34,7 @@ evslicer: evslicer.cpp inc/common.hpp inc/tinythread.hpp database.cpp sqlite3.o
$(CPP)
$(CPPFLAGS)
-o
evslicer evslicer.cpp database.cpp sqlite3.o
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
-o
evslicer evslicer.cpp database.cpp sqlite3.o
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evmlmotion
:
evmlmotion.cpp inc/common.hpp inc/tinythread.hpp database.cpp sqlite3.o
evmlmotion
:
evmlmotion.cpp inc/common.hpp inc/tinythread.hpp database.cpp sqlite3.o
$(CPP)
$(CPPFLAGS)
-o
evmlmotion evmlmotion.cpp database.cpp sqlite3.o
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
-o
evmlmotion evmlmotion.cpp database.cpp sqlite3.o
$(LIBFFMPEG)
$(HEADERS)
$(LIBOPENCV)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
rtspr
:
rtsp-relay.cpp
rtspr
:
rtsp-relay.cpp
$(CPP)
$(CPPFLAGS)
-o
rtspr rtsp-relay.cpp
$(LIBFFMPEG)
$(LIBS)
$(CPP)
$(CPPFLAGS)
-o
rtspr rtsp-relay.cpp
$(LIBFFMPEG)
$(LIBS)
...
...
opencv-motion-detect/evmlmotion.cpp
浏览文件 @
20f473e2
...
@@ -40,7 +40,7 @@ private:
...
@@ -40,7 +40,7 @@ private:
// load from db
// load from db
vector
<
int
>
*
sliceIdxToName
=
NULL
;
vector
<
int
>
*
sliceIdxToName
=
NULL
;
int
*
streamList
=
NULL
;
int
*
streamList
=
NULL
;
int
streamIdx
=
0
;
int
streamIdx
=
-
1
;
int
init
()
int
init
()
{
{
...
@@ -253,114 +253,66 @@ protected:
...
@@ -253,114 +253,66 @@ protected:
zmq_msg_t
msg
;
zmq_msg_t
msg
;
AVPacket
packet
,
keyPacket
;
AVPacket
packet
,
keyPacket
;
av_init_packet
(
&
keyPacket
);
av_init_packet
(
&
keyPacket
);
while
(
true
)
{
while
(
true
)
{
auto
start
=
chrono
::
system_clock
::
now
();
if
(
checkStop
()
==
true
)
{
auto
end
=
start
;
bStopSig
=
true
;
string
name
=
to_string
(
chrono
::
duration_cast
<
chrono
::
seconds
>
(
start
.
time_since_epoch
()).
count
())
+
".mp4"
;
break
;
name
=
urlOut
+
"/"
+
name
;
ret
=
avformat_alloc_output_context2
(
&
pAVFormatRemux
,
NULL
,
"mp4"
,
name
.
c_str
());
if
(
ret
<
0
)
{
spdlog
::
error
(
"evmlmotion {} {} failed create avformatcontext for output: %s"
,
sn
,
iid
,
av_err2str
(
ret
));
exit
(
1
);
}
}
// business logic
for
(
int
i
=
0
;
i
<
pAVFormatInput
->
nb_streams
;
i
++
)
{
int
ret
=
zmq_msg_init
(
&
msg
);
if
(
streamList
[
i
]
!=
-
1
)
{
ret
=
zmq_recvmsg
(
pSub
,
&
msg
,
0
);
out_stream
=
avformat_new_stream
(
pAVFormatRemux
,
NULL
);
if
(
ret
<
0
)
{
if
(
!
out_stream
)
{
spdlog
::
error
(
"failed to recv zmq msg: {}"
,
zmq_strerror
(
ret
));
spdlog
::
error
(
"evmlmotion {} {} failed allocating output stream 1"
,
sn
,
iid
);
continue
;
ret
=
AVERROR_UNKNOWN
;
}
ret
=
avcodec_parameters_copy
(
out_stream
->
codecpar
,
pAVFormatInput
->
streams
[
i
]
->
codecpar
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"evmlmotion {} {} failed to copy codec parameters"
,
sn
,
iid
);
}
}
}
}
ret
=
AVPacketSerializer
::
decode
((
char
*
)
zmq_msg_data
(
&
msg
),
ret
,
&
packet
);
//av_dump_format(pAVFormatRemux, 0, name.c_str(), 1);
{
if
(
!
(
pAVFormatRemux
->
oformat
->
flags
&
AVFMT_NOFILE
))
{
ret
=
avio_open2
(
&
pAVFormatRemux
->
pb
,
name
.
c_str
(),
AVIO_FLAG_WRITE
,
NULL
,
&
pOptsRemux
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
spdlog
::
error
(
"evmlmotion {} {} could not open output file {}"
,
sn
,
iid
,
name
);
spdlog
::
error
(
"packet decode failed: {:d}"
,
ret
);
continue
;
}
}
}
}
ret
=
avformat_write_header
(
pAVFormatRemux
,
&
pOptsRemux
);
zmq_msg_close
(
&
msg
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"evmlmotion {} {} error occurred when opening output file"
,
sn
,
iid
);
}
if
(
keyPacket
.
buf
!=
NULL
)
{
AVStream
*
in_stream
=
NULL
,
*
out_stream
=
NULL
;
ret
=
av_interleaved_write_frame
(
pAVFormatRemux
,
&
packet
);
in_stream
=
pAVFormatInput
->
streams
[
packet
.
stream_index
];
if
(
ret
<
0
)
{
packet
.
stream_index
=
streamList
[
packet
.
stream_index
];
spdlog
::
error
(
"evmlmotion {} {} failed write last key packet"
,
sn
,
iid
);
out_stream
=
pAVFormatRemux
->
streams
[
packet
.
stream_index
];
//calc pts
{
if
(
pktCnt
%
1024
==
0
)
{
spdlog
::
info
(
"seq: {}, pts: {}, dts: {}, dur: {}, idx: {}"
,
pktCnt
,
packet
.
pts
,
packet
.
dts
,
packet
.
duration
,
packet
.
stream_index
);
}
}
pktCnt
++
;
packet
.
pts
=
av_rescale_q_rnd
(
packet
.
pts
,
in_stream
->
time_base
,
out_stream
->
time_base
,
(
AVRounding
)(
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
));
packet
.
dts
=
av_rescale_q_rnd
(
packet
.
dts
,
in_stream
->
time_base
,
out_stream
->
time_base
,
(
AVRounding
)(
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
));
packet
.
duration
=
av_rescale_q
(
packet
.
duration
,
in_stream
->
time_base
,
out_stream
->
time_base
);
packet
.
pos
=
-
1
;
}
}
// TODO:
spdlog
::
info
(
"writing new slice {}"
,
name
.
c_str
());
if
(
packet
.
data
[
5
]
==
0x65
)
{
while
(
chrono
::
duration_cast
<
chrono
::
seconds
>
(
end
-
start
).
count
()
<
minutes
*
60
)
{
spdlog
::
info
(
"pktCnt: {}, keyframe: {:0x}"
,
pktCnt
,
packet
.
data
[
5
]);
if
(
checkStop
()
==
true
)
{
if
(
keyPacket
.
buf
!=
NULL
)
{
bStopSig
=
true
;
av_packet_unref
(
&
keyPacket
);
break
;
av_packet_ref
(
&
keyPacket
,
&
packet
);
}
// business logic
int
ret
=
zmq_msg_init
(
&
msg
);
ret
=
zmq_recvmsg
(
pSub
,
&
msg
,
0
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to recv zmq msg: {}"
,
zmq_strerror
(
ret
));
continue
;
}
ret
=
AVPacketSerializer
::
decode
((
char
*
)
zmq_msg_data
(
&
msg
),
ret
,
&
packet
);
{
if
(
ret
<
0
)
{
spdlog
::
error
(
"packet decode failed: {:d}"
,
ret
);
continue
;
}
}
zmq_msg_close
(
&
msg
);
AVStream
*
in_stream
=
NULL
,
*
out_stream
=
NULL
;
in_stream
=
pAVFormatInput
->
streams
[
packet
.
stream_index
];
packet
.
stream_index
=
streamList
[
packet
.
stream_index
];
out_stream
=
pAVFormatRemux
->
streams
[
packet
.
stream_index
];
//calc pts
{
if
(
pktCnt
%
1024
==
0
)
{
spdlog
::
info
(
"seq: {}, pts: {}, dts: {}, dur: {}, idx: {}"
,
pktCnt
,
packet
.
pts
,
packet
.
dts
,
packet
.
duration
,
packet
.
stream_index
);
}
pktCnt
++
;
packet
.
pts
=
av_rescale_q_rnd
(
packet
.
pts
,
in_stream
->
time_base
,
out_stream
->
time_base
,
(
AVRounding
)(
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
));
packet
.
dts
=
av_rescale_q_rnd
(
packet
.
dts
,
in_stream
->
time_base
,
out_stream
->
time_base
,
(
AVRounding
)(
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
));
packet
.
duration
=
av_rescale_q
(
packet
.
duration
,
in_stream
->
time_base
,
out_stream
->
time_base
);
packet
.
pos
=
-
1
;
}
// TODO:
if
(
packet
.
data
[
5
]
==
0x65
)
{
spdlog
::
info
(
"pktCnt: {}, keyframe: {:0x}"
,
pktCnt
,
packet
.
data
[
5
]);
if
(
keyPacket
.
buf
!=
NULL
)
{
av_packet_unref
(
&
keyPacket
);
av_packet_ref
(
&
keyPacket
,
&
packet
);
}
}
ret
=
av_interleaved_write_frame
(
pAVFormatRemux
,
&
packet
);
av_packet_unref
(
&
packet
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"error muxing packet"
);
}
}
}
end
=
chrono
::
system_clock
::
now
();
ret
=
av_interleaved_write_frame
(
pAVFormatRemux
,
&
packet
);
}
// while in slice
av_packet_unref
(
&
packet
);
// write tail
if
(
ret
<
0
)
{
av_write_trailer
(
pAVFormatRemux
);
spdlog
::
error
(
"error muxing packet"
);
// close output context
}
if
(
pAVFormatRemux
&&
!
(
pAVFormatRemux
->
oformat
->
flags
&
AVFMT_NOFILE
))
}
// while in slice
avio_closep
(
&
pAVFormatRemux
->
pb
);
// write tail
avformat_free_context
(
pAVFormatRemux
);
av_write_trailer
(
pAVFormatRemux
);
}
// close output context
if
(
pAVFormatRemux
&&
!
(
pAVFormatRemux
->
oformat
->
flags
&
AVFMT_NOFILE
))
avio_closep
(
&
pAVFormatRemux
->
pb
);
avformat_free_context
(
pAVFormatRemux
);
}
}
public
:
public
:
EvMLMotion
()
{
EvMLMotion
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论