海康摄像机使用问题

因为项目中需要用到海康的私有流解码显示,为了效率高,所以直接采用他们提供的解码库
碰到的问题

1.显示:海康显示是可以直接传入句柄,QT中的句柄winId
2.在显示中点击label的时候,会响应主界面的paintEvent,之后QLabel显示区域会闪烁,特别是在添加拖动之后
解决方法

1.显示的时候直接强行转成HWND,传入:(HWND)ui.label->winId;

2.为了不影响没有预览时候对label的操作,可以在预览视频之后将ui.label->setUpdatesEnabled(false),之后对label进行操作都不会引起窗体闪烁,关闭视频之后ui.label->setUpdatesEnabled(true)

使用rtsp流进行显示

rtsp://admin:xxxx密码@10.17.162.101:554/h264/ch1/main/av_stream



bool YV12ToBGR24_FFmpeg(unsigned char* pYUV,unsigned char* pBGR24,int width,int height)
{
    if (width < 1 || height < 1 || pYUV == NULL || pBGR24 == NULL)
        return false;
    //int srcNumBytes,dstNumBytes;
    //uint8_t *pSrc,*pDst;
    AVPicture pFrameYUV,pFrameBGR;

    //pFrameYUV = avpicture_alloc();
    //srcNumBytes = avpicture_get_size(PIX_FMT_YUV420P,width,height);
    //pSrc = (uint8_t *)malloc(sizeof(uint8_t) * srcNumBytes);
    avpicture_fill(&pFrameYUV,pYUV,PIX_FMT_YUV420P,width,height);

    //U,V互换
    uint8_t * ptmp=pFrameYUV.data[1];
    pFrameYUV.data[1]=pFrameYUV.data[2];
    pFrameYUV.data [2]=ptmp;

    //pFrameBGR = avcodec_alloc_frame();
    //dstNumBytes = avpicture_get_size(PIX_FMT_BGR24,width,height);
    //pDst = (uint8_t *)malloc(sizeof(uint8_t) * dstNumBytes);
    avpicture_fill(&pFrameBGR,pBGR24,PIX_FMT_BGR24,width,height);

    struct SwsContext* imgCtx = NULL;
    imgCtx = sws_getContext(width,height,PIX_FMT_YUV420P,width,height,PIX_FMT_BGR24,SWS_BILINEAR,0,0,0);

    if (imgCtx != NULL){
        sws_scale(imgCtx,pFrameYUV.data,pFrameYUV.linesize,0,height,pFrameBGR.data,pFrameBGR.linesize);
        if(imgCtx){
            sws_freeContext(imgCtx);
            imgCtx = NULL;
        }
        return true;
    }
    else{
        sws_freeContext(imgCtx);
        imgCtx = NULL;
        return false;
    }
}


猜你喜欢

转载自blog.csdn.net/chongzi865458/article/details/79482005