video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2020-10-09 d64868c215e35088bfeda67aeb04db0800bf2844
csrc/ffmpeg/format/FormatIn.cpp
@@ -2,6 +2,8 @@
#include <stdexcept>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
extern "C"{
#include <libavformat/avformat.h>
@@ -198,6 +200,16 @@
      return ctx_->streams[vs_idx_]->codecpar->codec_id == AV_CODEC_ID_HEVC;
   }
   const bool FormatIn::isAVC1()const{
      if (IsHEVC()) return false;
      char p[100] = {0};
      char *sub = av_fourcc_make_string(p, ctx_->streams[vs_idx_]->codecpar->codec_tag);
      const int ret = strcmp(sub, "avc1");
      if (ret == 0) return true;
      return false;
   }
   bool FormatIn::openCodec(AVDictionary **options){
      if (vs_idx_ == -1) return false;
@@ -211,14 +223,32 @@
      int idle_gpu = -1;
      srand((unsigned)time(NULL));
constexpr int need = 350; // M
constexpr int reserved = 512; // M
      for (int i = 0; i < 2; ++i)
      {
         if(hw_accl_){
                idle_gpu = gpu::getGPUPrior(350, 896, 0);
                // idle_gpu = gpu::getGPU(300);
            // 设置gpu index
               if (prop_->gpu_index_ > -1){
                   idle_gpu = prop_->gpu_index_;
                  if (!gpu::satisfy(prop_->gpu_index_, need, reserved)){
                     hw_accl_ = false;
                     continue;
               }
                   idle_gpu = prop_->gpu_index_;
               }else{
                   idle_gpu = gpu::getGPUPrior(need, reserved, 0);
                   // idle_gpu = gpu::getGPU(300);
               usleep(2000000 + rand()%3000000);
               if (!gpu::satisfy(idle_gpu, need, reserved)){
                     hw_accl_ = false;
                     continue;
                  }
               }
                if(idle_gpu < 0){
                    logIt("NO GPU RESOURCE TO DECODE");
                    hw_accl_ = false;