From 64fed650d429fdbdfa4011956a2c057dd0348914 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 13 十一月 2019 14:21:59 +0800
Subject: [PATCH] bug fix

---
 csrc/wrapper.cpp |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp
index 86662a1..6e067d9 100644
--- a/csrc/wrapper.cpp
+++ b/csrc/wrapper.cpp
@@ -370,10 +370,14 @@
         int br;
         int gi;
         int flag;
+        int fmt;
         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, const int fmt, const char *file){
+
+        if (fmt < 0) return NULL;
 
         PicEncoder *e = (PicEncoder*)malloc(sizeof(PicEncoder));
         e->enc = NULL;
@@ -383,6 +387,7 @@
         e->br = br;
         e->gi = gi;
         e->flag = scale_flag;
+        e->fmt = fmt;
         e->bridge = NULL;
 
         VideoProp prop_;
@@ -392,7 +397,10 @@
         prop_.bit_rate_ = br;
         gi < 0 ? prop_.gpu_acc_ = false : prop_.gpu_acc_ = true;
 
-		FormatOut *enc = new FormatOut(prop_, "./88.mp4");
+        std::string filename("./88.mp4");
+        if (file) filename = file;
+
+		FormatOut *enc = new FormatOut(prop_, filename.c_str());
         e->enc = enc;
 
         return e;
@@ -415,14 +423,17 @@
         PicEncoder *e = (PicEncoder*)hdl;
         auto ctx = e->enc->getCodecContext();
 
-        AVPixelFormat pix_fmt = AV_PIX_FMT_BGR24;
+        // AVPixelFormat pix_fmt = AV_PIX_FMT_BGR24;
         if (e->bridge == NULL){
             e->bridge = new cvbridge(
-                    w, h, AV_PIX_FMT_BGR24,
+                    w, h, e->fmt,
                     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, e->fmt);
+        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