1

在我们的应用程序中,我们需要传输视频,我们使用 Camera 类来捕获缓冲区并发送到目的地,

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

对于 500X300 缓冲区,我们收到 230400 字节的缓冲区,

我想知道,这是预期的缓冲区大小吗?
我相信尺寸会是

Y 平面 = 宽 * 高 = 500X300 = 150000

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

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

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

谁能解释一下,如果我需要获取每个组件的步幅值,我该如何获取

有没有办法得到它?

4

4 回答 4

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;
    }
于 2011-12-19T15:35:37.067 回答
0

我猜Android文档已经解释过了:

http://developer.android.com/reference/android/graphics/ImageFormat.html#YV12

于 2011-12-19T15:42:10.443 回答
0

我认为这很简单。从 android 中检查 YUVImage 类。您可以从来自相机预览的字节 [] 数据构建 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();
于 2011-12-19T22:51:25.660 回答
0

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

这个页面还说:

对于 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
于 2017-02-06T06:17:45.833 回答