video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-11-22 3f1386db26fc1d8d7b615907d21d0f196780eda2
update
3个文件已修改
55 ■■■■ 已修改文件
csrc/ffmpeg/data/PicData.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/worker/decoder.cpp 51 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/worker/decoder.hpp 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/ffmpeg/data/PicData.cpp
@@ -46,7 +46,7 @@
    bool PicData::init_AVPicture(){
        data_size_ = avpicture_get_size((AVPixelFormat)pix_fmt_,
                                         width_, height_);
        if(data_size_ < 0){
        if(data_size_ <= 0){
            logIt("avpicture_get_size error");
            return false;
        }
csrc/worker/decoder.cpp
@@ -20,14 +20,10 @@
{
    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);
@@ -52,31 +48,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 = rFrame->width;
        frm.height = rFrame->height;
        frm.format = rFrame->format;
        frm.width = frame->width;
        frm.height = frame->height;
        frm.format = frame->format;
        frm.id = id;
        frm.data = cvbridge::extractFrame(rFrame, &frm.length);
        uint8_t *origin = cvbridge::extractFrame(frame, &frm.length);
        if (!origin) return -1;
        if (conv && cFrame) av_frame_free(&cFrame);
        uint8_t *finale = NULL;
        if (frame->format != AV_PIX_FMT_NV12){
            finale = (uint8_t*)malloc(frm.length);
            unsigned char* SrcU = origin + frm.width * frm.height;
            unsigned char* SrcV = SrcU + frm.width * frm.height / 4 ;
            unsigned char* DstU = finale + frm.width * frm.height;
            memcpy(finale, origin, frm.width * frm.height);
            int i = 0;
            for( i = 0 ; i < frm.width * frm.height / 4 ; i++ ){
                *(DstU++) = *(SrcU++);
                *(DstU++) = *(SrcV++);
            }
            free(origin);
        }else{
            finale = origin;
        }
        frm.data = finale;
        std::lock_guard<std::mutex> l(mutex_frm_);
        while(list_frm_.size() > 50){
csrc/worker/decoder.hpp
@@ -18,7 +18,6 @@
{
    class FormatIn;
    class CodedData;
    class cvbridge;
} // namespace ffwrapper
namespace cffmpeg_wrap
@@ -37,7 +36,6 @@
    private:
        ffwrapper::FormatIn *decRef_;
        ffwrapper::cvbridge *conv_;
        
        std::list<FRM> list_frm_;
        std::mutex mutex_frm_;