2011-12-19 56 views
0

在我们的应用中,我们需要传输视频,我们使用Camera类捕获缓冲和发送到目的地,Android的YUV图像格式

我已经设置格式是YV12作为相机参数来接收缓冲区,

为为500x300缓冲,我们收到的230400个字节的缓冲区,

我想知道,这是预期的缓冲区的大小?
相信大小将是

Y平面=宽×高=为500x300 = 150000

Ù平面=宽度/ 2 *高度/ 2 = = 37500

V平面=宽度/ 2 *高度/ 2 = = 37500

       ======== 
           225000          
           ======== 

谁能解释我,如果我需要得到每个组件的步幅值,我怎么能拿到

有什么办法可以得到它吗?

回答

3

我可以告诉你如何可以从这个获得INT RGB []:

public int[] decodeYUV420SP(byte[] yuv420sp, int width, int height) { 

     final int frameSize = width * height; 

     int rgb[] = new int[width * height]; 
     for (int j = 0, yp = 0; j < height; j++) { 
      int uvp = frameSize + (j >> 1) * width, u = 0, v = 0; 
      for (int i = 0; i < width; i++, yp++) { 
       int y = (0xff & ((int) yuv420sp[yp])) - 16; 
       if (y < 0) 
        y = 0; 
       if ((i & 1) == 0) { 
        v = (0xff & yuv420sp[uvp++]) - 128; 
        u = (0xff & yuv420sp[uvp++]) - 128; 
       } 

       int y1192 = 1192 * y; 
       int r = (y1192 + 1634 * v); 
       int g = (y1192 - 833 * v - 400 * u); 
       int b = (y1192 + 2066 * u); 

       if (r < 0) 
        r = 0; 
       else if (r > 262143) 
        r = 262143; 
       if (g < 0) 
        g = 0; 
       else if (g > 262143) 
        g = 262143; 
       if (b < 0) 
        b = 0; 
       else if (b > 262143) 
        b = 262143; 

       rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000) 
         | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff); 

      } 
     } 
     return rgb; 
    } 
+0

谢谢,但我们不希望它是转换为RGB,我们想在事实上压缩到通一个只将数据转换成YUV格式的解码器,只有这个东西是,我们不知道如何调整步长值。 – Amitg2k12 2011-12-19 15:43:21

0

我认为这是简单的。 从android中chekout YUVImage类。您可以从来自相机预览的byte []数据构造YUV图像。 你可以这样写:

//width and height you get it from camera properties, image width and height of camera preview 
YuvImage image=new YuvImage(data, ImageFormat.NV21, int width, int height, null); 
byte[] newData = image.getYuvData(); 
//or if you want int format = image.getYuvFormat(); 
0

这是一个很古老的问题,但我已经对同样的问题挣扎了几天。所以我决定写一些评论来帮助别人。在Android开发者网站(here)中描述的YV12似乎不是YV12的一种,而是IMC1。该页面表示,y-stride和uv-stride都应该以16字节对齐。

而且也是本page说:

对于YV12,所接收的图像缓冲器不必紧紧 打包,因为可能在像素数据的每一行, 为一体的端部是填充描述在YV12中。

基于上述意见,我使用python命令行来计算它:

>>> w = 500 
>>> h = 300 
>>> y_stride = (500 + 15)/16 * 16.0 
>>> y_stride 
512.0 
>>> y_size = y_stride * h 
>>> y_size 
153600.0 
>>> uv_stride = (500/2 + 15)/16 * 16.0 
>>> uv_stride 
256.0 
>>> u_size = uv_stride * h/2 
>>> v_size = uv_stride * h/2 
>>> size = y_size + u_size + v_size 
>>> size 
230400.0