video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-10-23 98d01a35d01aa0b0f172590da545d489fc49637d
add fps get
7个文件已修改
28 ■■■■■ 已修改文件
cffmpeg.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/cffmpeg.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.cpp 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.hpp 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
goffmpeg.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.c 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.h 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cffmpeg.h
@@ -15,6 +15,7 @@
void c_ffmpeg_destroy(const cffmpeg h);
void c_ffmpeg_run(const cffmpeg h, const char *input);
int c_ffmpeg_get_fps(const cffmpeg h);
void c_ffmpeg_run_gb28181(const cffmpeg h);
void c_ffmepg_use_cpu(const cffmpeg h);
/////////passive api
csrc/cffmpeg.cpp
@@ -33,6 +33,11 @@
    s->RunStream(input);
}
int c_ffmpeg_get_fps(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    return s->GetFPS();
}
void c_ffmpeg_run_gb28181(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    s->GB28181();
csrc/wrapper.cpp
@@ -52,6 +52,7 @@
    ,decoder_(nullptr)
    ,rec_(new rec)
    ,logit_(false)
    ,fps_(25)
    {
        makeTheWorld();
    }
@@ -189,6 +190,8 @@
                continue;
            }
            fps_ = in->getFPS();
            int wTime = 1000000.0 / in->getFPS() ;
            wTime >>= 1;
            logIt("WAIT TIME PER FRAME: %d", wTime);
csrc/wrapper.hpp
@@ -50,6 +50,8 @@
        void CPUDec(){cpu_ = 1;}
        void AudioSwitch(const bool a);
        void SetRecMinCacheTime(const int mind);
        int GetFPS(){return fps_;}
    public: //decoder
        void BuildDecoder();
        void GetPicDecoder(unsigned char **data, int *w, int *h, int *format, int *length, int64_t *id);
@@ -74,6 +76,7 @@
        // 录像请求缓存,等待runstream后添加
        std::function<void()> fn_rec_lazy_;
        bool logit_;
        int fps_;
    };
    uint8_t* Decode(const char *file, const int gb, int *w, int *h);
goffmpeg.go
@@ -94,3 +94,8 @@
    C.wrap_fn_run(unsafe.Pointer(libcffmpeg), h.ffmpeg, in)
}
// FPS fps
func (h *GoFFMPEG) FPS() int {
    return int(C.wrap_fn_fps(unsafe.Pointer(libcffmpeg), h.ffmpeg))
}
libcffmpeg.c
@@ -63,6 +63,14 @@
    fn_run(h, input);
}
int wrap_fn_fps(void *lib, const cffmpeg h){
    if(!fn_fps){
        fn_fps = (lib_cffmpeg_fps)dlsym(lib, "c_ffmpeg_get_fps");
        if (!fn_fps) return 25;
    }
    return fn_fps(h);
}
void wrap_fn_run_gb28181(void *lib, const cffmpeg h){
    if (!fn_gb28181){
        fn_gb28181 = (lib_cffmpeg_gb28181)dlsym(lib, "c_ffmpeg_run_gb28181");
libcffmpeg.h
@@ -14,6 +14,7 @@
typedef cffmpeg(*lib_cffmpeg_create2)(const char*);
typedef void (*lib_cffmpeg_destroy)(const cffmpeg);
typedef void (*lib_cffmpeg_run)(const cffmpeg, const char*);
typedef int (*lib_cffmpeg_fps)(const cffmpeg);
typedef void (*lib_cffmpeg_gb28181)(const cffmpeg);
typedef void (*lib_cffmpeg_cpu)(const cffmpeg);
typedef void (*lib_cffmpeg_rec_duration)(const cffmpeg, const int, const int);
@@ -29,6 +30,7 @@
static lib_cffmpeg_create2             fn_create2 = NULL;
static lib_cffmpeg_destroy             fn_destroy = NULL;
static lib_cffmpeg_run                 fn_run = NULL;
static lib_cffmpeg_fps                 fn_fps = NULL;
static lib_cffmpeg_gb28181             fn_gb28181 = NULL;
static lib_cffmpeg_cpu                 fn_cpu = NULL;
static lib_cffmpeg_rec_duration        fn_rec_duration = NULL;
@@ -48,6 +50,7 @@
cffmpeg wrap_fn_create2(void *lib, const char *logfile);
void wrap_fn_destroy(void *lib, const cffmpeg h);
void wrap_fn_run(void *lib, const cffmpeg h, const char* input);
int wrap_fn_fps(void *lib, const cffmpeg h);
void wrap_fn_run_gb28181(void *lib, const cffmpeg h);
void wrap_fn_use_cpu(void *lib, const cffmpeg h);
void wrap_fn_rec_duration(void *lib, const cffmpeg h, const int min, const int max);