直接传入image_t输出检测结果

#include "H264DecoderThread.h"
#include "Poco/Thread.h"  
#include<iostream>
#include<fstream>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>

using namespace std;
using Poco::Thread;

FFmpegErrorCode H264DecoderThread::connect()
{
    AVDictionary *opts = 0;
    av_dict_set(&opts, "rtsp_transport", "tcp", 0);
    av_dict_set(&opts, "stimeout", "1000000", 0);
    FFmpegErrorCode res = FFmpeg_NoError;

    printf("H264DecoderThread connect()\n");

    do 
    {
        if (avformat_open_input(&m_pFormatCtx, m_strMrl.c_str(), NULL, &opts) != 0)
        {
            res = FFmpeg_ConnectFail;
            break;
        }

        if (avformat_find_stream_info(m_pFormatCtx, NULL) < 0)
        {
            res = FFmpeg_FindStreamInfo;
            break;
        }

        m_nVideoStreamIndex = av_find_best_stream(m_pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
        if (m_nVideoStreamIndex < 0)
        {
            res = FFmpeg_FindBestStream;
            break;
        }
        AVStream* st = m_pFormatCtx->streams[m_nVideoStreamIndex];
        AVCodec *pCodec = avcodec_find_decoder(st->codec->codec_id);
        if (!pCodec || avcodec_open2(st->codec, pCodec, NULL) < 0)
        {
            res = FFmpeg_FindDecoder;
            break;
        }
    } while (false);
    if (res != FFmpeg_NoError)
    {
        avformat_close_input(&m_pFormatCtx);
    }
    else
    {
        m_bConnected = true;

        string names_file = "coco.names";
        string cfg_file = "yolov3.cfg";
        string weights_file = "yolov3.weights";

       pDetector = new Detector(cfg_file, weights_file);
        
        if (pDetector == NULL) 
        {
            printf("error pDetector == NULL\n");
        }

        #if 0
        m_dst_pix_fmt = AV_PIX_FMT_RGB24;
        m_dst_w = 1280;
        m_dst_h = 720;
        m_dst_c = 3;
        #else
        m_dst_pix_fmt = AV_PIX_FMT_BGR24;
        m_dst_w = 416;
        m_dst_h = 416;
        m_dst_c = 3;
        #endif
        
    }
    av_dict_free(&opts);
    return res;
}

void H264DecoderThread::AddTask(PicInfo &picInfo)
{
    
    printf("H264DecoderThread AddTask()\n");
}


static image_t my_make_empty_image(int w, int h, int c)
{
    image_t out;
    out.data = 0;
    out.h = h;
    out.w = w;
    out.c = c;
    return out;
}

static image_t my_make_image_custom(int w, int h, int c)
{
    image_t out = my_make_empty_image(w, h, c);
    out.data = (float *)calloc(h*w*c, sizeof(float));
    return out;
}

void H264DecoderThread::run()
{
    printf("H264DecoderThread run()\n");

    AVFrame *frame = av_mallocz(sizeof(*frame));
    printf("H264DecoderThread run()sizeof(*frame) %d\n", sizeof(*frame));
    printf("H264DecoderThread run()sizeof(AVFrame) %d\n", sizeof(AVFrame));
    /*
    H264DecoderThread run()sizeof(*frame) 488
    H264DecoderThread run()sizeof(AVFrame) 488
  */
    AVCodecContext* avctx = m_pFormatCtx->streams[m_nVideoStreamIndex]->codec;
    //sws_scale将输入参数, 转成RGB24
      /*
  enum AVPixelFormat {
      AV_PIX_FMT_NONE = -1,
      AV_PIX_FMT_YUV420P,   ///< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
      AV_PIX_FMT_YUYV422,   ///< packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
      AV_PIX_FMT_RGB24,     ///< packed RGB 8:8:8, 24bpp, RGBRGB

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值