video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-11-21 0d5ec550ad724aac0a019a5cd619330af7cbc572
updte
2个文件已修改
39 ■■■■ 已修改文件
csrc/worker/decoder.cpp 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/worker/decoder.hpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/worker/decoder.cpp
@@ -20,10 +20,14 @@
{
    decoder::decoder(ffwrapper::FormatIn *dec)
    :decRef_(dec)
    ,conv_(NULL)
    {}
    
    decoder::~decoder(){
        if (conv_){
            delete conv_;
            conv_ = NULL;
        }
        std::lock_guard<std::mutex> l(mutex_frm_);
        for(auto i : list_frm_){
            free(i.data);
@@ -48,13 +52,32 @@
    }
    int decoder::saveFrame(AVFrame *frame, const int64_t &id){
        AVFrame *cFrame = NULL;
        bool conv = false;
        if (frame->format != AV_PIX_FMT_NV12){
            if (!conv_){
                conv_ = new cvbridge(
                    frame->width, frame->height, frame->format,
                    frame->width, frame->height, AV_PIX_FMT_NV12);
            }
            if (conv_){
                cFrame = conv_->convert2Frame(frame);
                if (!cFrame) return -1;
                conv = true;
            }
        }
        AVFrame * rFrame = frame;
        if (conv && cFrame) rFrame = cFrame;
        FRM frm;
        frm.width = frame->width;
        frm.height = frame->height;
        frm.format = frame->format;
        frm.width = rFrame->width;
        frm.height = rFrame->height;
        frm.format = rFrame->format;
        frm.id = id;
        frm.data = cvbridge::extractFrame(frame, &frm.length);
        frm.data = cvbridge::extractFrame(rFrame, &frm.length);
        if (conv && cFrame) av_frame_free(&cFrame);
        std::lock_guard<std::mutex> l(mutex_frm_);
        while(list_frm_.size() > 50){
            for(int i = 0; i < 12; i++){
csrc/worker/decoder.hpp
@@ -18,6 +18,7 @@
{
    class FormatIn;
    class CodedData;
    class cvbridge;
} // namespace ffwrapper
namespace cffmpeg_wrap
@@ -36,7 +37,8 @@
    private:
        ffwrapper::FormatIn *decRef_;
        ffwrapper::cvbridge *conv_;
        std::list<FRM> list_frm_;
        std::mutex mutex_frm_;