video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-09-24 93f44a10e2e8942e57e62bb210a2ca7d206a51b7
csrc/worker/rec.cpp
@@ -3,6 +3,10 @@
#include <unistd.h>
#include <sys/time.h>
extern "C"{
#include <libavcodec/avcodec.h>
}
#include "../ffmpeg/format/FormatIn.hpp"
#include "../ffmpeg/data/CodedData.hpp"
#include "../ffmpeg/log/log.hpp"
@@ -181,12 +185,14 @@
        std::lock_guard<std::mutex> l(mtx_pkt_);
        //wait I 
        if (list_pkt_.empty()) {
            AVPacket &avpkt = data->getAVPacket();
            if (!(avpkt.flags & AV_PKT_FLAG_KEY)){
            if (!(data->getAVPacket().flags & AV_PKT_FLAG_KEY)){
                return;
            }
        }
        list_pkt_.push_back({data, id});
        // 超过缓存最大长度,删除一个gop
        shrinkCache();
    }
@@ -194,12 +200,12 @@
    int rec::shrinkCache(){
        //超过最大缓存,丢弃gop
        //缓存最小长度的,用于记录
        while (list_pkt_.size() > minduration_/2) {
        int md = minduration_ < 201 ? 200 : minduration_;
        while (list_pkt_.size() > md/2) {
            list_pkt_.pop_front();
            while(!list_pkt_.empty()){
                auto &cache = list_pkt_.front();
                AVPacket &avpkt = cache.data->getAVPacket();
                if (!(avpkt.flags & AV_PKT_FLAG_KEY)){
                auto &i = list_pkt_.front();
                if (!(i.data->getAVPacket().flags & AV_PKT_FLAG_KEY)){
                    list_pkt_.pop_front();
                }else{
                    break;