在做视频回调解码时,需要用到数据转换,找了很多,后来公司同事写了一个,基本上可以通用,发出来给大家分享下。
/// <summary>
/// 将YV12转换成RGB32
/// </summary>
/// <param name="pYU12">yv12数据</param>
/// <param name="lPicHeight">图片高度</param>
/// <param name="lPicWidth">图片宽度</param>
/// <returns></returns>
public static byte[] GetRgb32_From_Yv12(IntPtr pYV12, Int32 lPicHeight, Int32 lPicWidth)
{
// YUV平面
byte[] pYPlaneByte = new byte[lPicHeight * lPicWidth];
byte[] pUPlaneByte = new byte[(lPicHeight / 2) * (lPicWidth / 2)];
byte[] pVPlaneByte = new byte[(lPicHeight / 2) * (lPicWidth / 2)];
// 根据解码数据首地址及分量长度,进行地址偏移,获取各YUV分量