iOS libyuv開源庫,ioslibyuv開源

來源:互聯網
上載者:User

iOS libyuv開源庫,ioslibyuv開源
libyuv是Google開源庫,可用作映像資料格式的轉換,比如視頻流編解碼時格式的轉換,YUV資料轉化RGB等

libyuv靜態庫

為了方便使用,已經將libyuv原始碼打包成了iOS靜態庫,libyuv靜態庫

libyuv使用

下面以nv12(yuv420sp)轉化為I420(yuv420p)為例:

void nv12_to_yuv420p(unsigned char* nv12, unsigned char* yuv420p, int width, int height) {

int y_size = width * height;

int u_size = y_size / 4;

int v_size = u_size;

int uv_size = u_size + v_size;

unsigned char *src_y = malloc(y_size);

unsigned char *src_uv = malloc(uv_size);

memcpy(src_y, nv12, y_size);

memcpy(src_uv, nv12 + y_size, uv_size);

unsigned char *dst_y = malloc(y_size);

unsigned char *dst_u = malloc(u_size);

unsigned char *dst_v = malloc(v_size);

int src_stride_y = width;

int src_stride_uv = width;

int dst_stride_y = width;

int dst_stride_u = width >> 1;

int dst_stride_v = dst_stride_u;

NV12ToI420(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, width, height);

memcpy(yuv420p, dst_y, y_size);

memcpy(yuv420p + y_size, dst_u, u_size);

memcpy(yuv420p + y_size + u_size, dst_v, v_size);

free(src_y);

free(src_uv);

free(dst_y);

free(dst_u);

free(dst_v);

}

nv12轉化yuv420p實現方法有多種,比如利用libyuv,ffmpeg,除了利用第三方庫實現轉化,也可以自己實現,代碼如下:

void yuv420sp_to_yuv420p(unsigned char* yuv420sp, unsigned char* yuv420p, int width, int height)

{

int i, j;

int y_size = width * height;

unsigned char* y = yuv420sp;

unsigned char* uv = yuv420sp + y_size;

unsigned char* y_tmp = yuv420p;

unsigned char* u_tmp = yuv420p + y_size;

unsigned char* v_tmp = yuv420p + y_size * 5 / 4;

memcpy(y_tmp, y, y_size);

for (j = 0, i = 0; j < y_size/2; j+=2, i++)

{

u_tmp[i] = uv[j];

v_tmp[i] = uv[j+1];

}

}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.