提交 2bbecf82 authored 作者: blu's avatar blu

init

上级 5ae4475e
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
......@@ -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
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论