From dc65b072a13994ff02cc7b54f3b00ba087e7f86a Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期三, 20 十一月 2019 14:05:52 +0800 Subject: [PATCH] add zerocopy --- csrc/wrapper.cpp | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp index 86662a1..dc511fa 100644 --- a/csrc/wrapper.cpp +++ b/csrc/wrapper.cpp @@ -373,7 +373,8 @@ cvbridge *bridge; } PicEncoder; - void *CreateEncoder(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi){ + void *CreateEncoder(const int w, const int h, const int fps, const int br, + const int scale_flag, const int gi){ PicEncoder *e = (PicEncoder*)malloc(sizeof(PicEncoder)); e->enc = NULL; @@ -415,14 +416,16 @@ PicEncoder *e = (PicEncoder*)hdl; auto ctx = e->enc->getCodecContext(); - AVPixelFormat pix_fmt = AV_PIX_FMT_BGR24; if (e->bridge == NULL){ e->bridge = new cvbridge( w, h, AV_PIX_FMT_BGR24, e->w, e->h, ctx->pix_fmt, e->flag); } - AVFrame *frame = cvbridge::fillFrame(in, w, h, pix_fmt); + AVFrame *bgr_frame = cvbridge::fillFrame(in, w, h, AV_PIX_FMT_BGR24); + AVFrame *frame = e->bridge->convert2Frame(bgr_frame); + av_frame_free(&bgr_frame); + AVPacket *pkt = av_packet_alloc(); auto flag = e->enc->encode(pkt, frame); -- Gitblit v1.8.0