Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
2bbecf82
提交
2bbecf82
authored
8月 02, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
5ae4475e
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
37 行增加
和
20 行删除
+37
-20
Makefile
opencv-motion-detect/Makefile
+17
-9
motion_files.py
opencv-motion-detect/motion_files.py
+3
-3
rtsp.c
opencv-motion-detect/rtsp.c
+17
-8
没有找到文件。
opencv-motion-detect/Makefile
浏览文件 @
2bbecf82
CC
=
g++
CFLAGS
=
-g
-Wall
-std
=
c++11
CC
=
gcc
CPP
=
g++
CPPFLAGS
=
-g
-Wall
-std
=
c++11
CFLAGS
=
-g
-Wall
cvsrc
=
prog1.cpp
cvprog
=
cvprog
rtspsrc
=
rtsp.cpp
rtspprog
=
rtspprog
OPENCV
=
`
pkg-config opencv
--cflags
--libs
`
FFMPEG
=
`
pkg-config libavformat libavutil libavcodec
--cflags
--libs
`
$(cvprog)
:
$(cvsrc)
$(CC)
$(CFLAGS)
-o
$(cvprog)
$(cvsrc)
$(OPENCV)
all
:
cvprog mux rtsp
$(rtspprog)
:
$(rtspsrc)
$(CC)
$(CFLAGS)
-o
$(rtspprog)
$(rtspsrc)
$(FFMPEG)
\ No newline at end of file
rtsp
:
rtsp.c
$(CC)
$(CFLAGS)
-o
rtsp rtsp.c
$(FFMPEG)
cvprog
:
prog1.cpp
$(CPP)
$(CPPFLAGS)
-o
$(cvprog)
$(cvsrc)
$(OPENCV)
mux
:
demuxing_decoding.c
$(CC)
$(CFLAGS)
-o
mux demuxing_decoding.c
$(FFMPEG)
clean
:
rm
-fr
rtsp cvprog mux
\ No newline at end of file
opencv-motion-detect/motion_files.py
浏览文件 @
2bbecf82
...
...
@@ -45,11 +45,11 @@ class FrameFetcher(Thread):
try
:
self
.
frameCnt
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_POS_FRAMES
)
self
.
frameHolder
.
append
({
'f'
:
frame
,
't'
:
start
,
's'
:
self
.
frameCnt
})
if
self
.
frameCnt
%
(
self
.
fps
*
2
)
==
0
:
if
self
.
frameCnt
%
(
self
.
fps
*
5
)
==
0
:
print
(
"frameCnt: "
,
self
.
frameCnt
)
except
:
self
.
failedPutCnt
+=
1
if
self
.
failedPutCnt
%
(
self
.
fps
*
2
)
==
0
:
if
self
.
failedPutCnt
%
(
self
.
fps
*
5
)
==
0
:
print
(
"failedPutCnt: "
,
self
.
failedPutCnt
)
finally
:
self
.
frameCnt
+=
1
...
...
@@ -253,7 +253,7 @@ class EventConsumer(Thread):
if
__name__
==
'__main__'
:
env
=
{}
env
[
'VIDEO_ADDR'
]
=
os
.
getenv
(
'VIDEO_ADDR'
,
'/tmp/test'
)
#'rtsp://172.31.0.121/live/0/sub')
env
[
'VIDEO_ADDR'
]
=
os
.
getenv
(
'VIDEO_ADDR'
,
'/tmp/test'
)
#
'rtsp://172.31.0.121/live/0/sub')
env
[
'PROC_FPS'
]
=
int
(
os
.
getenv
(
'PROC_FPS'
,
10
))
sensitivity_base
=
20
...
...
opencv-motion-detect/rtsp.c
浏览文件 @
2bbecf82
...
...
@@ -163,8 +163,11 @@ int main(int argc, const char *argv[])
if
(
pPacket
->
stream_index
==
video_stream_index
)
{
logging
(
"AVPacket->pts %"
PRId64
,
pPacket
->
pts
);
response
=
decode_packet
(
pPacket
,
pCodecContext
,
pFrame
);
if
(
response
<
0
)
break
;
if
(
response
<
0
){
// logging("decode_packet error: %s", av_err2str(response));
continue
;
}
// stop it, otherwise we'll be saving hundreds of frames
if
(
--
how_many_packets_to_process
<=
0
)
break
;
}
...
...
@@ -197,6 +200,7 @@ static int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFra
// Supply raw packet data as input to a decoder
// https://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga58bc4bf1e0ac59e27362597e467efff3
int
response
=
avcodec_send_packet
(
pCodecContext
,
pPacket
);
int
ret
=
-
1
;
if
(
response
<
0
)
{
logging
(
"Error while sending a packet to the decoder: %s"
,
av_err2str
(
response
));
...
...
@@ -208,15 +212,18 @@ static int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFra
// https://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c
response
=
avcodec_receive_frame
(
pCodecContext
,
pFrame
);
if
(
response
==
AVERROR
(
EAGAIN
)
||
response
==
AVERROR_EOF
)
{
logging
(
"Error response: %s"
,
av_err2str
(
response
));
//frame packet consumed, read next frame from AVFormatContext
// logging("Error response: %s", av_err2str(response));
// response = 0;
// no frame extraced
break
;
}
else
if
(
response
<
0
)
{
if
(
response
<
0
)
{
logging
(
"Error while receiving a frame from the decoder: %s"
,
av_err2str
(
response
));
return
response
;
}
if
(
response
>=
0
)
{
}
else
{
logging
(
"Frame %d (type=%c, size=%d bytes) pts %d key_frame %d [DTS %d]"
,
pCodecContext
->
frame_number
,
...
...
@@ -231,9 +238,11 @@ static int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFra
snprintf
(
frame_filename
,
sizeof
(
frame_filename
),
"%s-%d.pgm"
,
"frame"
,
pCodecContext
->
frame_number
);
// save a grayscale frame into a .pgm file
save_gray_frame
(
pFrame
->
data
[
0
],
pFrame
->
linesize
[
0
],
pFrame
->
width
,
pFrame
->
height
,
frame_filename
);
ret
=
0
;
}
}
return
0
;
return
ret
;
}
static
void
save_gray_frame
(
unsigned
char
*
buf
,
int
wrap
,
int
xsize
,
int
ysize
,
char
*
filename
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论