From 31e0d0c171b4d6a7dc9b9697e69e165651d3fe93 Mon Sep 17 00:00:00 2001 From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674> Date: 星期三, 28 十二月 2016 18:32:20 +0800 Subject: [PATCH] face detect ok --- RtspFace/PL_H264Encoder.cpp | 34 +++++++++++++++++++++++++++------- 1 files changed, 27 insertions(+), 7 deletions(-) diff --git a/RtspFace/PL_H264Encoder.cpp b/RtspFace/PL_H264Encoder.cpp index 5547256..33ffc40 100644 --- a/RtspFace/PL_H264Encoder.cpp +++ b/RtspFace/PL_H264Encoder.cpp @@ -5,8 +5,9 @@ { #include <libavcodec/avcodec.h> #include <libavutil/frame.h> - #include <libavformat/avformat.h> #include <libavutil/imgutils.h> + #include <libavutil/opt.h> + #include <libavformat/avformat.h> #include <libyuv.h> } @@ -104,11 +105,12 @@ in->pAVCodecContext->height = 600;//#todo from config in->pAVCodecContext->time_base.num=1; in->pAVCodecContext->time_base.den=25; - in->pAVCodecContext->gop_size = 25; + in->pAVCodecContext->gop_size = 2; in->pAVCodecContext->max_b_frames = 0; + //in->pAVCodecContext->profile = FF_PROFILE_H264_MAIN; in->pAVCodecContext->pix_fmt = AV_PIX_FMT_YUV420P; - //av_opt_set(c->priv_data, "preset", "superfast", 0); + av_opt_set(in->pAVCodecContext->priv_data, "preset", "superfast", 0); //av_opt_set(c->priv_data, "tune", "zerolatency", 0); if(avcodec_open2(in->pAVCodecContext, avCodec, NULL) >= 0) @@ -261,6 +263,17 @@ return !(in->payError); } +bool encodeH264(H264Encoder_Internal* in, uint8_t* buffer, timeval pts) +{ + AVFrame avFrame; + avFrame.width = 1920;//#todo + avFrame.height = 1080; + avFrame.data[0] = buffer; + avFrame.data[1] = buffer + 1920*1080; + avFrame.data[2] = buffer + 1920*1080 + 1920*1080/4; + return encodeH264(in, &avFrame, pts); +} + bool PL_H264Encoder::pay(const PipeMaterial& pm) { H264Encoder_Internal* in = (H264Encoder_Internal*)internal; @@ -289,13 +302,20 @@ return false; MB_Frame* frame = (MB_Frame*)pm.buffer; - if (frame->type != MB_Frame::MBFT_PTR_AVFRAME) + + bool ret; + + if (frame->type == MB_Frame::MBFT_PTR_AVFRAME) + ret = encodeH264(in, (AVFrame*)(frame->buffer), frame->pts); + else if (frame->type == MB_Frame::MBFT_YUV420) + ret = encodeH264(in, (uint8_t*)(frame->buffer), frame->pts); + else { - printf("PL_H264Encoder::pay only support MBFT_PTR_AVFRAME\n"); + printf("PL_H264Encoder::pay only support MBFT_PTR_AVFRAME / MBFT_YUV420\n"); + in->payError = true; return false; } - - bool ret = encodeH264(in, (AVFrame*)(frame->buffer), frame->pts); + in->payError = !ret; if (ret) -- Gitblit v1.8.0