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

init

上级 5ae4475e
CC = g++ CC = gcc
CFLAGS = -g -Wall -std=c++11 CPP = g++
CPPFLAGS = -g -Wall -std=c++11
CFLAGS = -g -Wall
cvsrc = prog1.cpp cvsrc = prog1.cpp
cvprog = cvprog cvprog = cvprog
rtspsrc=rtsp.cpp
rtspprog=rtspprog
OPENCV = `pkg-config opencv --cflags --libs` OPENCV = `pkg-config opencv --cflags --libs`
FFMPEG = `pkg-config libavformat libavutil libavcodec --cflags --libs` FFMPEG = `pkg-config libavformat libavutil libavcodec --cflags --libs`
$(cvprog):$(cvsrc) all:cvprog mux rtsp
$(CC) $(CFLAGS) -o $(cvprog) $(cvsrc) $(OPENCV)
$(rtspprog):$(rtspsrc) rtsp: rtsp.c
$(CC) $(CFLAGS) -o $(rtspprog) $(rtspsrc) $(FFMPEG) $(CC) $(CFLAGS) -o rtsp rtsp.c $(FFMPEG)
\ No newline at end of file
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): ...@@ -45,11 +45,11 @@ class FrameFetcher(Thread):
try: try:
self.frameCnt = self.cap.get(cv2.CAP_PROP_POS_FRAMES) self.frameCnt = self.cap.get(cv2.CAP_PROP_POS_FRAMES)
self.frameHolder.append({'f': frame, 't': start, 's': self.frameCnt}) 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) print("frameCnt: ", self.frameCnt)
except: except:
self.failedPutCnt += 1 self.failedPutCnt += 1
if self.failedPutCnt % (self.fps * 2) == 0: if self.failedPutCnt % (self.fps * 5) == 0:
print("failedPutCnt: ", self.failedPutCnt) print("failedPutCnt: ", self.failedPutCnt)
finally: finally:
self.frameCnt += 1 self.frameCnt += 1
...@@ -253,7 +253,7 @@ class EventConsumer(Thread): ...@@ -253,7 +253,7 @@ class EventConsumer(Thread):
if __name__ == '__main__': if __name__ == '__main__':
env = {} 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)) env['PROC_FPS'] = int(os.getenv('PROC_FPS', 10))
sensitivity_base = 20 sensitivity_base = 20
......
...@@ -163,8 +163,11 @@ int main(int argc, const char *argv[]) ...@@ -163,8 +163,11 @@ int main(int argc, const char *argv[])
if (pPacket->stream_index == video_stream_index) { if (pPacket->stream_index == video_stream_index) {
logging("AVPacket->pts %" PRId64, pPacket->pts); logging("AVPacket->pts %" PRId64, pPacket->pts);
response = decode_packet(pPacket, pCodecContext, pFrame); response = decode_packet(pPacket, pCodecContext, pFrame);
if (response < 0) if (response < 0){
break; // logging("decode_packet error: %s", av_err2str(response));
continue;
}
// stop it, otherwise we'll be saving hundreds of frames // stop it, otherwise we'll be saving hundreds of frames
if (--how_many_packets_to_process <= 0) break; if (--how_many_packets_to_process <= 0) break;
} }
...@@ -197,6 +200,7 @@ static int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFra ...@@ -197,6 +200,7 @@ static int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFra
// Supply raw packet data as input to a decoder // Supply raw packet data as input to a decoder
// https://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga58bc4bf1e0ac59e27362597e467efff3 // https://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga58bc4bf1e0ac59e27362597e467efff3
int response = avcodec_send_packet(pCodecContext, pPacket); int response = avcodec_send_packet(pCodecContext, pPacket);
int ret = -1;
if (response < 0) { if (response < 0) {
logging("Error while sending a packet to the decoder: %s", av_err2str(response)); 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 ...@@ -208,15 +212,18 @@ static int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFra
// https://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c // https://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c
response = avcodec_receive_frame(pCodecContext, pFrame); response = avcodec_receive_frame(pCodecContext, pFrame);
if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) { 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; break;
} }
else if (response < 0) {
if (response < 0) {
logging("Error while receiving a frame from the decoder: %s", av_err2str(response)); logging("Error while receiving a frame from the decoder: %s", av_err2str(response));
return response; return response;
} } else {
if (response >= 0) {
logging( logging(
"Frame %d (type=%c, size=%d bytes) pts %d key_frame %d [DTS %d]", "Frame %d (type=%c, size=%d bytes) pts %d key_frame %d [DTS %d]",
pCodecContext->frame_number, pCodecContext->frame_number,
...@@ -231,9 +238,11 @@ static int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFra ...@@ -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); snprintf(frame_filename, sizeof(frame_filename), "%s-%d.pgm", "frame", pCodecContext->frame_number);
// save a grayscale frame into a .pgm file // save a grayscale frame into a .pgm file
save_gray_frame(pFrame->data[0], pFrame->linesize[0], pFrame->width, pFrame->height, frame_filename); 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) static void save_gray_frame(unsigned char *buf, int wrap, int xsize, int ysize, char *filename)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论