Giter Club home page Giter Club logo

Comments (3)

doggycoder avatar doggycoder commented on August 25, 2024 1

@leestars 确定导出的YUV数据到底是NV21的,还是NV12的。output导出的数据是YUV的,但是YUV也有YUV420\YUV422\YUV420SP等等格式,建议先看下这些基础性的东西。

from audiovideo.

leestars avatar leestars commented on August 25, 2024

我查了资料,确实有很多种格式,我调用output方法,看打印出来的log是yuv420p,我用了下面这种方法将yuv转rgb,转出来的效果是一样的。

private int[] yuv420pToRgb(byte[] yuv420p,int width,int height) {
int frameSize = width * height;
int[] rgb = new int[frameSize];
int i = 0, j = 0,yp = 0;
int uvp = 0, u = 0, v = 0;
for (j = 0, yp = 0; j < height; j++) {
uvp = frameSize + (j >> 1) * width;
u = 0;
v = 0;
for (i = 0; i < width; i++, yp++)
{
int y = (0xff & ((int) yuv420p[yp])) - 16;
if (y < 0)
y = 0;
if ((i & 1) == 0)
{
v = (0xff & yuv420p[uvp++]) - 128;
u = (0xff & yuv420p[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;
}

有黑白图像,但是有绿色的紫色在上面,这种情况是不是y转对了,但是u和v没有转对?
@doggycoder

from audiovideo.

Xiqiao-Zhao avatar Xiqiao-Zhao commented on August 25, 2024

我查了资料,确实有很多种格式,我调用output方法,看打印出来的log是yuv420p,我用了下面这种方法将yuv转rgb,转出来的效果是一样的。

private int[] yuv420pToRgb(byte[] yuv420p,int width,int height) {
int frameSize = width * height;
int[] rgb = new int[frameSize];
int i = 0, j = 0,yp = 0;
int uvp = 0, u = 0, v = 0;
for (j = 0, yp = 0; j < height; j++) {
uvp = frameSize + (j >> 1) * width;
u = 0;
v = 0;
for (i = 0; i < width; i++, yp++)
{
int y = (0xff & ((int) yuv420p[yp])) - 16;
if (y < 0)
y = 0;
if ((i & 1) == 0)
{
v = (0xff & yuv420p[uvp++]) - 128;
u = (0xff & yuv420p[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;
}

有黑白图像,但是有绿色的紫色在上面,这种情况是不是y转对了,但是u和v没有转对?
@doggycoder
是不是UV的通道读错了,比如误将V通道读入了U通道数据

from audiovideo.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.