From dbf2d66ef422388631509b06243b194319c813bf Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期四, 21 十一月 2019 14:47:51 +0800 Subject: [PATCH] update --- csrc/wrapper.cpp | 8 +++++--- csrc/wrapper.hpp | 2 +- goffmpeg.go | 6 ++++++ cffmpeg.h | 2 +- goenc.go | 13 ++++++++++++- libcffmpeg.c | 4 ++-- csrc/cffmpeg.cpp | 4 ++-- libcffmpeg.h | 4 ++-- 8 files changed, 31 insertions(+), 12 deletions(-) diff --git a/cffmpeg.h b/cffmpeg.h index 796a57c..5abcf23 100644 --- a/cffmpeg.h +++ b/cffmpeg.h @@ -29,7 +29,7 @@ void* c_ffmpeg_get_avpacket(const cffmpeg h, int *size, int *key); // pic encoder -void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi); +void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi); void c_ffmpeg_destroy_encoder(void *h); int c_ffmpeg_encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key); diff --git a/csrc/cffmpeg.cpp b/csrc/cffmpeg.cpp index f77b232..f42d753 100644 --- a/csrc/cffmpeg.cpp +++ b/csrc/cffmpeg.cpp @@ -110,8 +110,8 @@ } // pic encoder -void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi){ - return CreateEncoder(w, h, fps, br, scale_flag, gi); +void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi){ + return CreateEncoder(w, h, fps, br, pix_fmt, scale_flag, gi); } void c_ffmpeg_destroy_encoder(void *h){ diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp index af25ea4..373ec37 100644 --- a/csrc/wrapper.cpp +++ b/csrc/wrapper.cpp @@ -307,12 +307,13 @@ int fps; int br; int gi; + int pix_fmt; int flag; cvbridge *bridge; } PicEncoder; void *CreateEncoder(const int w, const int h, const int fps, const int br, - const int scale_flag, const int gi){ + const int pix_fmt, const int scale_flag, const int gi){ PicEncoder *e = (PicEncoder*)malloc(sizeof(PicEncoder)); e->enc = NULL; @@ -321,6 +322,7 @@ e->fps = fps; e->br = br; e->gi = gi; + e->pix_fmt = pix_fmt; e->flag = scale_flag; e->bridge = NULL; @@ -356,11 +358,11 @@ if (e->bridge == NULL){ e->bridge = new cvbridge( - w, h, AV_PIX_FMT_BGR24, + w, h, e->pix_fmt, e->w, e->h, ctx->pix_fmt, e->flag); } - AVFrame *bgr_frame = cvbridge::fillFrame(in, w, h, AV_PIX_FMT_BGR24); + AVFrame *bgr_frame = cvbridge::fillFrame(in, w, h, e->pix_fmt); AVFrame *frame = e->bridge->convert2Frame(bgr_frame); av_frame_free(&bgr_frame); diff --git a/csrc/wrapper.hpp b/csrc/wrapper.hpp index fa7ad72..9b866a1 100644 --- a/csrc/wrapper.hpp +++ b/csrc/wrapper.hpp @@ -80,7 +80,7 @@ }; void *CreateEncoder(const int w, const int h, const int fps, const int br, - const int scale_flag, const int gi); + const int pix_fmt, const int scale_flag, const int gi); void DestroyEncoder(void *h); int Encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key); } diff --git a/goenc.go b/goenc.go index 858ed98..69aa3e4 100644 --- a/goenc.go +++ b/goenc.go @@ -21,7 +21,18 @@ } return &GoEncoder{ - enc: C.wrap_fn_create_encoder(unsafe.Pointer(libcffmpeg), C.int(w), C.int(h), C.int(fps), C.int(br), C.int(sFlag), C.int(gi)), + enc: C.wrap_fn_create_encoder(unsafe.Pointer(libcffmpeg), C.int(w), C.int(h), C.int(fps), C.int(br), C.int(DstFormat), C.int(sFlag), C.int(gi)), + } +} + +// NewEncoderWithPixFmt origin pix_fmt +func NewEncoderWithPixFmt(w, h, fps, br, pixFmt, sFlag, gi int) *GoEncoder { + if w <= 0 || h <= 0 { + return nil + } + + return &GoEncoder{ + enc: C.wrap_fn_create_encoder(unsafe.Pointer(libcffmpeg), C.int(w), C.int(h), C.int(fps), C.int(br), C.int(pixFmt), C.int(sFlag), C.int(gi)), } } diff --git a/goffmpeg.go b/goffmpeg.go index 4353113..5ed9343 100644 --- a/goffmpeg.go +++ b/goffmpeg.go @@ -39,6 +39,12 @@ ScaleSpline = 0x400 ) +// SrcFormat format NV +const SrcFormat = 23 + +// DstFormat format +const DstFormat = 3 + var libcffmpeg C.libcffmpeg // InitFFmpeg init ffmepg diff --git a/libcffmpeg.c b/libcffmpeg.c index 6237dde..3bebfa6 100644 --- a/libcffmpeg.c +++ b/libcffmpeg.c @@ -144,12 +144,12 @@ } // for encoder -cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int scale_flag, const int gi){ +cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi){ if (!fn_create_encoder){ fn_create_encoder = (lib_cffmpeg_create_encoder)dlsym(lib, "c_ffmpeg_create_encoder"); release_if_err(fn_create_encoder, lib); } - return fn_create_encoder(w, h, fps, br, scale_flag, gi); + return fn_create_encoder(w, h, fps, br, pix_fmt, scale_flag, gi); } void wrap_fn_destroy_encoder(void *lib, const cencoder h){ diff --git a/libcffmpeg.h b/libcffmpeg.h index 8a6d7f7..95523e7 100644 --- a/libcffmpeg.h +++ b/libcffmpeg.h @@ -60,7 +60,7 @@ void* wrap_fn_get_avpacket(void *lib, const cffmpeg h, int* size, int* key); // for encoder typedef void* cencoder; -typedef cencoder (*lib_cffmpeg_create_encoder)(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi); +typedef cencoder (*lib_cffmpeg_create_encoder)(const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi); typedef void (*lib_cffmpeg_destroy_encoder)(cencoder h); typedef int (*lib_cffmpeg_encode)(cencoder hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key); @@ -68,7 +68,7 @@ static lib_cffmpeg_destroy_encoder fn_destroy_encoder = NULL; static lib_cffmpeg_encode fn_encode = NULL; -cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int scale_flag, const int gi); +cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi); void wrap_fn_destroy_encoder(void *lib, const cencoder h); void* wrap_fn_encode(void *lib, cencoder hdl, void *in, const int w, const int h, int *out_size, int *key); -- Gitblit v1.8.0