iOS 视频直播开发笔记(六)

         在视频直播中,为了提高视频编码效率,可以对数据进行适当的转换,再送编码器,iOS对NV12的数据编码效率最高,以下是YUV420P互转NV12,NV21的简单算法。

1.YUV420P转NV12

void YUV420PtoNV12(unsigned char *Src, unsigned char* Dst,int Width,int Height){

unsigned char* SrcU = Src + Width * Height;

unsigned char* SrcV = SrcU + Width * Height / 4 ;

memcpy(Dst, Src, Width * Height);

unsigned char* DstU = Dst + Width * Height;

for(int i = 0 ; i < Width * Height / 4 ; i++ ){

( *DstU++) = ( *SrcU++);

( *DstU++) = ( *SrcV++);

}

}

2.NV12转YUV420P 

/*image_src is the source image, image_dst is the converted image */

void NV12_YUV420P(const unsigned char* image_src, unsigned char* image_dst, int image_width, int image_height){ 

unsigned char* p = image_dst; 

memcpy(p, image_src, image_width * image_height * 3 / 2); 

const unsi

你可能感兴趣的:(C++入门及项目实战宝典)