video analysis2.0拆分,ffmpeg封装go接口库
554325746@qq.com
2020-03-09 52b0ef0b8d617de555808f6e2dbeffa311711155
csrc/wrapper.cpp
@@ -55,6 +55,7 @@
    ,rec_(new rec)
    ,logit_(false)
    ,fps_(25)
    ,file_finished_(false)
    {
        makeTheWorld();
    }
@@ -73,6 +74,8 @@
    ,decoder_(nullptr)
    ,rec_(new rec)
    ,logit_(true)
    ,fps_(25)
    ,file_finished_(false)
    {
        makeTheWorld();
        logif::CreateLogger(logfile, true);
@@ -105,16 +108,19 @@
        prop.gpu_acc_ = !cpu_;
       std::unique_ptr<FormatIn> in(new FormatIn(prop.gpuAccl()));
       AVDictionary *avdic = prop.optsFormat();
       int flag = -1;
        if (gb_){
            flag = in->openGb28181(input, NULL);
        }else{
            flag = in->open(input, &avdic);
           AVDictionary *avdic = prop.optsFormat();
            if(avdic){
                flag = in->open(input, &avdic);
              av_dict_free(&avdic);
           }else{
                flag = in->open(input, NULL);
            }
        }
       if(avdic){
          av_dict_free(&avdic);
       }
        if(flag == 0){
            if(!in->findStreamInfo(NULL)){
                logIt("can't find video stream\n");
@@ -196,9 +202,12 @@
            fps_ = in->getFPS();
            
            int wTime = 1000000.0 / in->getFPS() ;
            if (fps_ < 1 || fps_ > 200){
                fps_ = 25;
            }
            int wTime = 1000000.0 / fps_ ;
            wTime >>= 1;
            logIt("WAIT TIME PER FRAME: %d", wTime);
            init_worker(in.get());
@@ -207,6 +216,11 @@
            int64_t a_id = id;
            bool exist = access(input_url_.c_str(), 0) == 0;
            if (exist){
                wTime <<= 1;
            }
            logIt("WAIT TIME PER FRAME: %d", wTime);
            while(!stop_stream_.load()){
                auto data(std::make_shared<CodedData>());
@@ -245,7 +259,11 @@
            }
            deinit_worker();
            if (exist) break;
            if (exist) {
                logIt("local file exist");
                file_finished_ = true;
                break;
            }
        }
    }
@@ -286,6 +304,15 @@
    }
    void Wrapper::GetPicDecoder(unsigned char **data, int *w, int *h, int *format, int *length, int64_t *id){
        if (file_finished_){
            *data = (unsigned char*)this;
            *w = 1080;
            *h = 720;
            *format = 23;
            *length = 12;
            *id = -10802020;
            return;
        }
        if (decoder_){
            decoder_->GetFrame(data, w, h, format, length, id);
        }
@@ -403,5 +430,26 @@
        return flag;
    }
    int GetGb28181Pic(const char *rtspUrl, char *retData, int *retDataLen){
        int ret = 0;
        std::string fn = rtspUrl;
        auto handle_gb28181 = new GB28181API;
        if(handle_gb28181->addCamera(fn) == -1){
            delete(handle_gb28181);
            logIt("do addCamera Error\n");
            return -1;
        }
        int retLen = handle_gb28181->capturePic(handle_gb28181, retData, retDataLen);
        if(retLen == 0){
            logIt("do capturePic failed:%d");
            ret = -1;
        }
        handle_gb28181->deleteCamera();
        return ret;
    }
}