Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
d24847b0
提交
d24847b0
authored
8月 17, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
85f633cd
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
20 行删除
+23
-20
evslicer.cpp
opencv-motion-detect/evslicer.cpp
+23
-20
没有找到文件。
opencv-motion-detect/evslicer.cpp
浏览文件 @
d24847b0
...
...
@@ -25,7 +25,7 @@ class EvSlicer: public TinyThread {
private
:
#define URLOUT_DEFAULT "slices"
#define NUM_DAYS_DEFAULT 2
#define MINUTES_PER_SLICE_DEFAULT 1
0
#define MINUTES_PER_SLICE_DEFAULT 1
// 2 days, 10 minutes per record
#define NUM_SLICES_DEFAULT (24 * NUM_DAYS_DEFAULT * 60 / MINUTES_PER_SLICE_DEFAULT)
void
*
pSubCtx
=
NULL
,
*
pReqCtx
=
NULL
;
// for packets relay
...
...
@@ -38,7 +38,6 @@ private:
AVDictionary
*
pOptsRemux
=
NULL
;
// load from db
vector
<
int
>
*
sliceIdxToName
=
NULL
;
AVCodecParameters
**
pArrAVCodecParameters
=
NULL
;
int
*
streamList
=
NULL
;
int
init
()
...
...
@@ -212,7 +211,7 @@ private:
}
}
// ret = avformat_alloc_output_context2(&pAVFormatRemux, NULL, "mp
4
", urlOut.c_str());
// ret = avformat_alloc_output_context2(&pAVFormatRemux, NULL, "mp
g
", urlOut.c_str());
// if (ret < 0) {
// spdlog::error("evslicer {} {} failed create avformatcontext for output: %s", sn, iid, av_err2str(ret));
// exit(1);
...
...
@@ -223,22 +222,23 @@ private:
int
streamIdx
=
0
;
// find all video & audio streams for remuxing
streamList
=
(
int
*
)
av_mallocz_array
(
pAVFormatInput
->
nb_streams
,
sizeof
(
*
streamList
));
pArrAVCodecParameters
=
(
AVCodecParameters
**
)
malloc
(
pAVFormatInput
->
nb_streams
*
sizeof
(
AVCodecParameters
*
));
for
(
int
i
=
0
;
i
<
pAVFormatInput
->
nb_streams
;
i
++
)
{
AVStream
*
out_stream
;
AVStream
*
in_stream
=
pAVFormatInput
->
streams
[
i
];
AVCodecParameters
*
in_codecpar
=
in_stream
->
codecpar
;
if
(
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_AUDIO
&&
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_VIDEO
)
{
pArrAVCodecParameters
[
i
]
=
NULL
;
streamList
[
i
]
=
-
1
;
continue
;
}
pArrAVCodecParameters
[
i
]
=
in_codecpar
;
streamList
[
i
]
=
streamIdx
++
;
}
// av_dict_set(&pOptsRemux, "movflags", "frag_keyframe+empty_moov+default_base_moof", 0);
for
(
int
i
=
0
;
i
<
pAVFormatInput
->
nb_streams
;
i
++
)
{
spdlog
::
info
(
"streamList[{:d}]: {:d}"
,
i
,
streamList
[
i
]);
}
//av_dict_set(&pOptsRemux, "movflags", "frag_keyframe+empty_moov+default_base_moof", 0);
return
ret
;
}
protected
:
...
...
@@ -263,14 +263,13 @@ protected:
}
for
(
int
i
=
0
;
i
<
pAVFormatInput
->
nb_streams
;
i
++
)
{
if
(
pArrAVCodecParameters
[
i
]
!=
NULL
)
{
if
(
streamList
[
i
]
!=
-
1
)
{
out_stream
=
avformat_new_stream
(
pAVFormatRemux
,
NULL
);
if
(
!
out_stream
)
{
spdlog
::
error
(
"evslicer {} {} failed allocating output stream 1"
,
sn
,
iid
);
ret
=
AVERROR_UNKNOWN
;
}
ret
=
avcodec_parameters_copy
(
out_stream
->
codecpar
,
pA
rrAVCodecParameters
[
i
]
);
ret
=
avcodec_parameters_copy
(
out_stream
->
codecpar
,
pA
VFormatInput
->
streams
[
i
]
->
codecpar
);
spdlog
::
info
(
"evslicer {} {} copied codepar"
,
sn
,
iid
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"evslicer {} {} failed to copy codec parameters"
,
sn
,
iid
);
...
...
@@ -278,13 +277,11 @@ protected:
}
}
av_dump_format
(
pAVFormatRemux
,
0
,
name
.
c_str
(),
1
);
//
av_dump_format(pAVFormatRemux, 0, name.c_str(), 1);
if
(
!
(
pAVFormatRemux
->
oformat
->
flags
&
AVFMT_NOFILE
))
{
spdlog
::
error
(
"evslicer {} {} failed allocating output stream 2"
,
sn
,
iid
);
ret
=
avio_open2
(
&
pAVFormatRemux
->
pb
,
name
.
c_str
(),
AVIO_FLAG_WRITE
,
NULL
,
&
pOptsRemux
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"evslicer {} {} could not open output file {}"
,
sn
,
iid
,
name
);
exit
(
1
);
}
}
...
...
@@ -293,7 +290,7 @@ protected:
spdlog
::
error
(
"evslicer {} {} error occurred when opening output file"
,
sn
,
iid
);
}
while
(
chrono
::
duration_cast
<
chrono
::
seconds
>
(
end
-
start
).
count
()
*
60
<
minutes
*
60
)
{
while
(
chrono
::
duration_cast
<
chrono
::
seconds
>
(
end
-
start
).
count
()
<
minutes
*
60
)
{
if
(
checkStop
()
==
true
)
{
bStopSig
=
true
;
break
;
...
...
@@ -312,17 +309,24 @@ protected:
continue
;
}
}
zmq_msg_close
(
&
msg
);
// relay
if
(
packet
.
flags
&
AV_PKT_FLAG_KEY
)
{
spdlog
::
info
(
"pktCnt: {}, keyframe"
,
pktCnt
);
}
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
{
spdlog
::
debug
(
"seq: {:lld}, pts: {:lld}, dts: {:lld}, dur: {:lld}, idx: {:d}"
,
pktCnt
,
packet
.
pts
,
packet
.
dts
,
packet
.
duration
,
packet
.
stream_index
);
/* copy packet */
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
);
...
...
@@ -334,7 +338,6 @@ protected:
if
(
ret
<
0
)
{
spdlog
::
error
(
"error muxing packet"
);
}
spdlog
::
debug
(
"packet stream indx: {:d}"
,
packet
.
stream_index
);
end
=
chrono
::
steady_clock
::
now
();
}
// while in slice
...
...
@@ -357,7 +360,7 @@ public:
int
main
(
int
argc
,
const
char
*
argv
[])
{
spdlog
::
set_level
(
spdlog
::
level
::
debug
);
spdlog
::
set_level
(
spdlog
::
level
::
info
);
EvSlicer
es
;
es
.
join
();
return
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论