ios学习

CVPixelBufferRef取出RDB和YUV

2017-11-15  本文已影响307人  ai___believe

取出YUV

-(int) getImageData:(const CVImageBufferRef&) imageBuffer senddata:(unsigned char)data
{
int w,h,linesizey,linesizeuv;
unsigned char
srcy=NULL;
unsigned char* srcu=NULL;
unsigned char* srcv=NULL;

CVPixelBufferLockBaseAddress(imageBuffer, 0);
int count=CVPixelBufferGetPlaneCount(imageBuffer);
//printf("CVPixelBufferGetPlaneCount=%d\n",count);

if (CVPixelBufferIsPlanar(imageBuffer)) {
    w = CVPixelBufferGetWidth(imageBuffer);
    h = CVPixelBufferGetHeight(imageBuffer);
    
    // printf("w: %d,h: %d.\n",w,h);
    
    linesizey = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0);
    linesizeuv = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 1);
    // printf("CVPixelBufferGetBytesPerRowOfPlane is ok.\n");
    srcy = (unsigned char*) CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0);
    srcu = (unsigned char*) CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 1);
    srcv = (unsigned char*) CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 2);
    
    memcpy(data,srcy,720*1280);
    memcpy(data+720*1280,srcu,720*1280/4);
    memcpy(data+720*1280*5/4,srcv,720*1280/4);
    
    // printf("CVPixelBufferGetBaseAddressOfPlane is ok.\n");
}
else
{
    printf("CVPixelBufferIsPlanar error\n");
    return -1;
}
return 0;

}

取出RGB

}

http://www.bubuko.com/infodetail-526746.html

上一篇下一篇

猜你喜欢

热点阅读