video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-09-27 0c98249d381d6e56c78d6e752a49e768a4c4d22e
lib log fix
8个文件已修改
83 ■■■■ 已修改文件
cffmpeg.h 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/buz/recorder.cpp 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/cffmpeg.cpp 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.cpp 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.hpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
goffmpeg.go 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.c 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.h 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cffmpeg.h
@@ -9,7 +9,9 @@
typedef void* cffmpeg;
cffmpeg c_ffmpeg_create(const int, const char *logfile);
cffmpeg c_ffmpeg_create();
cffmpeg c_ffmpeg_create2(const char *logfile);
void c_ffmpeg_destroy(const cffmpeg h);
void c_ffmpeg_run(const cffmpeg h, const char *input);
csrc/buz/recorder.cpp
@@ -74,7 +74,16 @@
            
            int pid = getpid();
            file_path_ = dir_ + "/" + sole::uuid4().base62() + "-" + std::to_string(pid) + ".mp4";
            auto ret = out_->JustWriter(in_->getStream(AVMEDIA_TYPE_VIDEO), in_->getStream(AVMEDIA_TYPE_AUDIO), file_path_.c_str());
            auto v = in_->getStream(AVMEDIA_TYPE_VIDEO);
            if (!v){
                return -2;
            }
            AVStream *a = in_->getStream(AVMEDIA_TYPE_AUDIO);
            if (!audio){
                a = NULL;
            }
            auto ret = out_->JustWriter(v, a, file_path_.c_str());
            if (ret){
                logIt("start record file: %s", file_path_.c_str());
                return 0;
csrc/cffmpeg.cpp
@@ -10,17 +10,17 @@
}
#endif
#ifndef LIB_CFFMPEG
#include "csrc/all.hpp"
#endif
#include "csrc/wrapper.hpp"
using namespace cffmpeg_wrap;
cffmpeg c_ffmpeg_create(const int log, const char *logfile){
    bool logit = false;
    if (log != 0) logit = true;
    return new Wrapper(logit, logfile);
cffmpeg c_ffmpeg_create(){
    return new Wrapper();
}
cffmpeg c_ffmpeg_create2(const char *logfile){
    return new Wrapper(logfile);
}
void c_ffmpeg_destroy(const cffmpeg h){
csrc/wrapper.cpp
@@ -38,7 +38,7 @@
namespace cffmpeg_wrap{
    using namespace buz;
    Wrapper::Wrapper(const bool logit, const char *logfile)
    Wrapper::Wrapper()
    :input_url_("")
    ,scale_w_(0)
    ,scale_h_(0)
@@ -52,11 +52,29 @@
    ,stream_(nullptr)
    ,decoder_(nullptr)
    ,rec_(new rec)
    ,logit_(false)
    {
        makeTheWorld();
        if (logit){
            logif::CreateLogger(logfile, true);
        }
    Wrapper::Wrapper(const char *logfile)
    :input_url_("")
    ,scale_w_(0)
    ,scale_h_(0)
    ,scale_f_(SWS_POINT)
    ,audio_(false)
    ,gb_(0)
    ,cpu_(0)
    ,run_dec_(false)
    ,thread_(nullptr)
    ,stop_stream_(false)
    ,stream_(nullptr)
    ,decoder_(nullptr)
    ,rec_(new rec)
    ,logit_(true)
    {
        makeTheWorld();
        logif::CreateLogger(logfile, true);
    }
@@ -74,6 +92,7 @@
        {
            logIt("WRAPPER EXCEPTION: ", e.what());
        }
        if (logit_)
        logif::DestroyLogger();
    }
csrc/wrapper.hpp
@@ -27,7 +27,8 @@
    class Wrapper{
    public:
        explicit Wrapper(const bool logit, const char *logfile);
        Wrapper();
        explicit Wrapper(const char *logfile);
        ~Wrapper ();
    private: 
        std::unique_ptr<ffwrapper::FormatIn> init_reader(const char* input);
@@ -75,6 +76,7 @@
        rec* rec_;
        // 录像请求缓存,等待runstream后添加
        std::function<void()> fn_rec_lazy_;
        bool logit_;
    };
    uint8_t* Decode(const char *file, const int gb, int *w, int *h);
goffmpeg.go
@@ -76,10 +76,7 @@
// New 2nd new
func New(conf Config) *GoFFMPEG {
    var l *C.char
    logit := 0
    f := C.wrap_fn_create(C.int(logit), l)
    f := C.wrap_fn_create()
    if f == nil {
        return nil
@@ -104,8 +101,7 @@
    lf := C.CString(logfile)
    defer C.free(unsafe.Pointer(lf))
    logit := 1
    f := C.wrap_fn_create(C.int(logit), lf)
    f := C.wrap_fn_create2(lf)
    if f == nil {
        return nil
    }
libcffmpeg.c
@@ -19,6 +19,8 @@
    if(lib){
        fn_create = (lib_cffmpeg_create)dlsym(lib, "c_ffmpeg_create");
        release_if_err(fn_create, lib);
        fn_create2 = (lib_cffmpeg_create)dlsym(lib, "c_ffmpeg_create2");
        release_if_err(fn_create2, lib);
        fn_destroy = (lib_cffmpeg_destroy)dlsym(lib, "c_ffmpeg_destroy");
        release_if_err(fn_destroy, lib);
        fn_run = (lib_cffmpeg_run)dlsym(lib, "c_ffmpeg_run");
@@ -63,8 +65,12 @@
    }
}
cffmpeg wrap_fn_create(const int log, const char *logfile){
    return fn_create(log, logfile);
cffmpeg wrap_fn_create(){
    return fn_create();
}
cffmpeg wrap_fn_create2(const char *logfile){
    return fn_create2(logfile);
}
void wrap_fn_destroy(const cffmpeg h){
libcffmpeg.h
@@ -10,7 +10,8 @@
typedef void* cffmpeg;
typedef cffmpeg(*lib_cffmpeg_create)(const int, const char*);
typedef cffmpeg(*lib_cffmpeg_create)();
typedef cffmpeg(*lib_cffmpeg_create2)(const char*);
typedef void (*lib_cffmpeg_destroy)(const cffmpeg);
typedef void (*lib_cffmpeg_run)(const cffmpeg, const char*);
typedef void (*lib_cffmpeg_scale)(const cffmpeg, const int, const int, const int);
@@ -25,6 +26,7 @@
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;
static lib_cffmpeg_destroy             fn_destroy = NULL;
static lib_cffmpeg_run                 fn_run = NULL;
static lib_cffmpeg_scale               fn_scale = NULL;
@@ -42,7 +44,8 @@
libcffmpeg init_libcffmpeg(const char *so_file);
void release_libcffmpeg(libcffmpeg lib);
cffmpeg wrap_fn_create(const int log, const char *logfile);
cffmpeg wrap_fn_create();
cffmpeg wrap_fn_create2(const char *logfile);
void wrap_fn_destroy(const cffmpeg h);
void wrap_fn_run(const cffmpeg h, const char* input);
void wrap_fn_scale(const cffmpeg h, const int wid, const int hei, const int flags);