yuv中yv12与nv12的转换

YV12 与 NV12 的简单区别如图:



ffmpeg解码得到的YUV420P格式YV12写BUFFER保存:

    for( j=0; jheight; j++){
    memcpy(yQueue_buf + ywrite_ptr + pVideoframe->width*j, pVideoframe->data[0] + pVideoframe->linesize[0]*j, pVideoframe->width);
    }
    ywrite_ptr += pVideoframe->width*j;
//        printf("Y write =%d\n",ywrite_ptr);
    for( j=0; jheight/2; j++){
        memcpy(yQueue_buf + ywrite_ptr + pVideoframe->width/2*j, pVideoframe->data[1] + pVideoframe->linesize[1]*j, pVideoframe->width/2);
    }
    ywrite_ptr += pVideoframe->width/2*j;
    for( j=0; jheight/2; j++){
        memcpy(yQueue_buf + ywrite_ptr + pVideoframe->width/2*j, pVideoframe->data[2] + pVideoframe->linesize[2]*j, pVideoframe->width/2);
    }
    ywrite_ptr += pVideoframe->width/2*j;

将YV12转为NV12发送至编码入口:

    w = pInfo.Width;
    h = pInfo.Height;
    pitch = pData.Pitch;
    ptr = pData.Y + pInfo.CropX + pInfo.CropY * pData.Pitch;
    for(i = 0; i < h; i++)
    {
        memcpy( ptr + i*pitch, YFrameBuf+w*i, w );
    }

    mfxU8 buf[1024];
    ptr = pData.UV + pInfo.CropX + (pInfo.CropY / 2) * pitch;
    for( i=0; i
(pitch为超出width的填充数据,主要为字节对齐,一般为16或32字节,原理同ffmpeg中的linesize中超出width的部分,在数据转换时需要注意留存空间 )



你可能感兴趣的:(图像/视频传输)