video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-11-21 9b12b43b25fd5a476205bc693be0cf836c281bc1
remove code not used
2个文件已删除
7个文件已修改
444 ■■■■■ 已修改文件
cffmpeg.h 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/cffmpeg.cpp 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.cpp 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.hpp 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
goconv.go 151 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
godecjpeg.go 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
goffmpeg.go 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.c 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.h 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cffmpeg.h
@@ -28,19 +28,10 @@
void* c_ffmpeg_get_pic_decoder(const cffmpeg h, int *wid, int *hei, int *format, int *length, int64_t *id);
void* c_ffmpeg_get_avpacket(const cffmpeg h, int *size, int *key);
//////decoder
void* c_ffmpeg_decode(const char *file, const int gb, int *wid, int *hei);
// 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_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);
// conv cpu
void *c_ffmpeg_create_conv(const int srcW, const int srcH, const int srcFormat,
                          const int dstW, const int dstH, const int dstFormat, const int flag);
void c_ffmpeg_destroy_conv(void *h);
void *c_ffmpeg_conv(void *h, uint8_t *in);
#ifdef __cplusplus
}
csrc/cffmpeg.cpp
@@ -109,11 +109,6 @@
    return data;
}
/////////////////////test
void* c_ffmpeg_decode(const char *file, const int gb, int *wid, int *hei){
    return Decode(file, gb, wid, hei);
}
// 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);
@@ -125,17 +120,4 @@
int c_ffmpeg_encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key){
    return Encode(hdl, in, w, h, out, size, key);
}
void *c_ffmpeg_create_conv(const int srcW, const int srcH, const int srcFormat,
                          const int dstW, const int dstH, const int dstFormat, const int flag){
    return CreateConvertor(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flag);
}
void *c_ffmpeg_conv(void *h, uint8_t *in){
    return Convert(h, in);
}
void c_ffmpeg_destroy_conv(void *h){
    DestoryConvertor(h);
}
csrc/wrapper.cpp
@@ -299,69 +299,6 @@
// return val: -1 open error; -2, find stream error; -3, converter create
namespace cffmpeg_wrap{ // start test functions
    uint8_t* Decode(const char *file, const int gb, int *w, int *h){
        VideoProp prop;
        prop.url_ = file;
        prop.gpu_acc_ = false;
        std::unique_ptr<FormatIn> in(new FormatIn(prop.gpuAccl()));
        int flag = -1;
        if (gb){
            flag = in->openGb28181(file, NULL);
        }else{
            flag = in->open(file, NULL);
        }
        std::unique_ptr<cvbridge> bridge_(nullptr);
        if(flag == 0){
            if(!in->findStreamInfo(NULL)){
                logIt("yolo can't find video stream\n");
                *w = *h = -2;
                return NULL;
            }
            auto flag = in->openCodec(NULL);
            if(flag){
                auto dec_ctx = in->getCodecContext();
                AVPixelFormat pix_fmt = AV_PIX_FMT_BGR24;
                bridge_.reset(new cvbridge(
                        dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
                        dec_ctx->width, dec_ctx->height, pix_fmt, SWS_BICUBIC));
            }else{
                logIt("FormatIn openCodec Failed!");
                *w = *h = -3;
                return NULL;
            }
        }else{
            logIt("open %s error", file);
            *w = *h = -1;
            return NULL;
        }
        uint8_t *pic = NULL;
        *w = *h = 0;
        int tryTime = 0;
        while (tryTime++ < 100){
            auto data(std::make_shared<CodedData>());
            if (in->readPacket(&data->getAVPacket()) == 0){
                auto frame(std::make_shared<FrameData>());
                AVFrame *frm = frame->getAVFrame();
                if(in->decode(frm, &data->getAVPacket()) == 0){
                    *w = frm->width;
                    *h = frm->height;
                    pic = bridge_->convert2Data(frm);
                    break;
                }
            }
        }
        return pic;
    }
/////// for encoder
    typedef struct _PicEncoder{
        FormatOut *enc;
@@ -453,57 +390,5 @@
        return flag;
    }
///////////////////////////////////////////////////////////
    typedef struct _conv
    {
        int srcW;
        int srcH;
        int srcF;
        int dstW;
        int dstH;
        cvbridge *b;
    }Conv;
    void *CreateConvertor(const int srcW, const int srcH, const int srcFormat,
                          const int dstW, const int dstH, const int dstFormat, const int flag){
        auto bridge = new cvbridge(
                srcW, srcH, srcFormat,
                dstW, dstH, dstFormat, flag);
        if (!bridge) return NULL;
        Conv *c = (Conv*)malloc(sizeof(Conv));
        c->b = bridge;
        c->dstW = dstW;
        c->dstH = dstH;
        c->srcW = srcW;
        c->srcH = srcH;
        c->srcF = srcFormat;
        return c;
    }
    uint8_t *Convert(void *h, uint8_t *src){
        Conv *c = (Conv*)h;
        auto b = c->b;
        AVFrame *tmp_frm = cvbridge::fillFrame(src, c->srcW, c->srcH, c->srcF);
        if (!tmp_frm) return NULL;
        unsigned char *picData = b->convert2Data(tmp_frm);
        av_frame_free(&tmp_frm);
        return picData;
    }
    void DestoryConvertor(void *h){
        Conv *c = (Conv*)h;
        delete c->b;
        free(c);
    }
}
csrc/wrapper.hpp
@@ -79,17 +79,10 @@
        int fps_;
    };
    uint8_t* Decode(const char *file, const int gb, int *w, int *h);
    void *CreateEncoder(const int w, const int h, const int fps, const int br, 
                        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);
    void *CreateConvertor(const int srcW, const int srcH, const int srcFormat,
                          const int dstW, const int dstH, const int dstFormat, const int flag);
    uint8_t *Convert(void *h, uint8_t *src);
    void DestoryConvertor(void *h);
}
#endif
goconv.go
File was deleted
godecjpeg.go
File was deleted
goffmpeg.go
@@ -12,6 +12,33 @@
    "unsafe"
)
const (
    // ScaleNone self add no scale raw frame data
    ScaleNone = 0
    // ScaleFastBilinear SWS_FAST_BILINEAR
    ScaleFastBilinear = 1
    // ScaleBilinear SWS_BILINEAR
    ScaleBilinear = 2
    // ScaleBicubic SWS_BICUBIC
    ScaleBicubic = 4
    // ScaleX SWS_X
    ScaleX = 8
    // ScalePoint SWS_POINT
    ScalePoint = 0x10
    // ScaleArea SWS_AREA
    ScaleArea = 0x20
    // ScaleBicublin SWS_BICUBLIN
    ScaleBicublin = 0x40
    // ScaleGauss SWS_GAUSS
    ScaleGauss = 0x80
    // ScaleSinc SWS_SINC
    ScaleSinc = 0x100
    // ScaleLancZos SWS_LANCZOS
    ScaleLancZos = 0x200
    // ScaleSpline SWS_SPLINE
    ScaleSpline = 0x400
)
var libcffmpeg C.libcffmpeg
// InitFFmpeg init ffmepg
libcffmpeg.c
@@ -143,15 +143,6 @@
    return fn_get_avpacket(h, size, key);
}
// return val: -1 open error; -2, find stream error; -3, converter create error
void* wrap_fn_decode(void *lib, const char* file, const int gb, int* wid, int* hei){
    if (!fn_decode){
        fn_decode = (lib_cffmpeg_decode)dlsym(lib, "c_ffmpeg_decode");
        release_if_err(fn_decode, lib);
    }
    return fn_decode(file, gb, wid, hei);
}
// 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){
    if (!fn_create_encoder){
@@ -183,31 +174,4 @@
    *out_size = 0;
    *key = 0;
    return NULL;
}
// for conv
cconv wrap_fn_create_conv(void *lib, const int srcW, const int srcH, const int srcFormat,
                          const int dstW, const int dstH, const int dstFormat, const int flag){
    if (!fn_create_conv){
        fn_create_conv = (lib_cffmpeg_create_conv)dlsym(lib, "c_ffmpeg_create_conv");
        release_if_err(fn_create_conv, lib);
    }
    return fn_create_conv(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flag);
}
void wrap_fn_destroy_conv(void *lib, const cconv h){
    if (!fn_destroy_conv){
        fn_destroy_conv = (lib_cffmpeg_destroy_conv)dlsym(lib, "c_ffmpeg_destroy_conv");
        if(!fn_destroy_conv) return;
    }
    fn_destroy_conv(h);
}
void* wrap_fn_conv(void *lib, const cconv h, uint8_t *in){
    if (!fn_conv){
        fn_conv = (lib_cffmpeg_conv)dlsym(lib, "c_ffmpeg_conv");
        release_if_err(fn_conv, lib);
    }
    return fn_conv(h, in);
}
libcffmpeg.h
@@ -24,7 +24,6 @@
typedef void (*lib_cffmpeg_decoder)(const cffmpeg);
typedef void*(*lib_cffmpeg_pic)(const cffmpeg, int*, int*, int*, int*, int64_t*);
typedef void*(*lib_cffmpeg_avpacket)(const cffmpeg, int*, int*);
typedef void*(*lib_cffmpeg_decode)(const char*, const int, int*, int*);
static lib_cffmpeg_create              fn_create = NULL;
static lib_cffmpeg_create2             fn_create2 = NULL;
@@ -40,7 +39,6 @@
static lib_cffmpeg_decoder             fn_decoder = NULL;
static lib_cffmpeg_pic                 fn_decoder_pic = NULL;
static lib_cffmpeg_avpacket            fn_get_avpacket = NULL;
static lib_cffmpeg_decode              fn_decode = NULL;
typedef void* libcffmpeg;
libcffmpeg init_libcffmpeg(const char *so_file);
@@ -60,7 +58,6 @@
void wrap_fn_decoder(void *lib, const cffmpeg h);
void* wrap_fn_decoder_pic(void *lib, const cffmpeg h, int *wid, int *hei, int *format, int *length, int64_t *id);
void* wrap_fn_get_avpacket(void *lib, const cffmpeg h, int* size, int* key);
void* wrap_fn_decode(void *lib, const char* file, const int gb, int* wid, int* hei);
// 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);
@@ -75,21 +72,6 @@
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);
// for conv
typedef void *cconv;
typedef cconv (*lib_cffmpeg_create_conv)(const int, const int, const int, const int, const int, const int, const int);
typedef void* (*lib_cffmpeg_conv)(const cconv, uint8_t *in);
typedef void (*lib_cffmpeg_destroy_conv)(const cconv);
static lib_cffmpeg_create_conv fn_create_conv = NULL;
static lib_cffmpeg_destroy_conv fn_destroy_conv = NULL;
static lib_cffmpeg_conv fn_conv = NULL;
cconv wrap_fn_create_conv(void *lib, const int srcW, const int srcH, const int srcFormat,
                          const int dstW, const int dstH, const int dstFormat, const int flag);
void wrap_fn_destroy_conv(void *lib, const cconv h);
void* wrap_fn_conv(void *lib, const cconv h, uint8_t *in);
#ifdef __cplusplus
}