在Android中将NV21转换为I420 [英] NV21 to I420 in android

查看:113
本文介绍了在Android中将NV21转换为I420的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个libyuv,它可以将NV21转换为I420,但是我真的不知道如何称呼它.

EDIT : I came across this libyuv that does the NV21 to I420 conversion, but i don't really understand how to call it.

// Convert NV21 to I420.  Same as NV12 but u and v pointers swapped.
LIBYUV_API
int NV21ToI420(const uint8* src_y, int src_stride_y,
           const uint8* src_vu, int src_stride_vu,
           uint8* dst_y, int dst_stride_y,
           uint8* dst_u, int dst_stride_u,
           uint8* dst_v, int dst_stride_v,
           int width, int height) 

我将从摄像机回调获得的NV21字节[]传递给jni层,如下所示将其转换为unsigned char *

I am passing the NV21 byte[] obtained from camera callback to the jni layer and converting it to unsigned char* as below

int yuvBufLen = env->GetArrayLength(yuvNV21);
unsigned char* yuvNV21Buf = new unsigned char[yuvBufLen];
env->GetByteArrayRegion(yuvNV21, 0, yuvBufLen,reinterpret_cast<jbyte*>(yuvNV21Buf));

现在我不清楚如何获取调用libyuv函数NV21ToI420所需的不同参数.以下每个参数代表什么? 如何从我有未签名的char * yuvNV21Buf中获取它们?

Now it is not clear to me how do i get the different parameters required to call the libyuv function NV21ToI420. What does each of the following parameters represent and how to obtain them from the unsigned char* yuvNV21Buf I have ??

const uint8 * src_y,
int src_stride_y,
const uint8 * src_vu,
int src_stride_vu,
uint8 * dst_y,
int dst_stride_y,
uint8 * dst_u,
int dst_stride_u,
uint8 * dst_v,
诠释dst_stride_v

const uint8* src_y,
int src_stride_y,
const uint8* src_vu,
int src_stride_vu,
uint8* dst_y,
int dst_stride_y,
uint8* dst_u,
int dst_stride_u,
uint8* dst_v,
int dst_stride_v

我已经检查了此在ios中获取yuv420 ,其中介绍了如何获取所有必需的参数来调用libyuv :: NV12ToI420

I have checked this obtain yuv420 in ios which explains how to get all the required parameters to call libyuv::NV12ToI420.

有人可以解释一下如何实现吗?

Can someone please explain me how to achieve this??

我正在通过下面的预览回调从相机捕获帧字节[]

I am capturing frame byte[] from camera through the preview callback below

@Override
        public void onPreviewFrame(byte[] frameData, Camera camera) {

正在获取的frameData为NV21格式,我正在尝试将NV21转换为I420.

The frameData am getting is in NV21 format and I am trying to convert NV21 to I420.

推荐答案

我无法使用我在问题中发布的方法,它一直崩溃.

I could not get to work the method I posted in the question, it kept crashing.

但是感谢彼得,我找到了这个 NV21ToI420 转换,它对我来说很完美.

But thanks to Peter I found this NV21ToI420 conversion and it worked perfect for me.

仅仅需要NV21和I420指针.

Simply it needs the NV21 and the I420 pointer.

unsigned char* yuvPtr; //NV21 data
unsigned char* I420 = new unsigned char[sourceWidth*sourceHeight*1.5]; //destination I420 pointer where the converted yuv will be stored 
NV21toI420(yuvPtr, I420, sourceWidth, sourceHeight);

仅此而已......

Thats all....

这篇关于在Android中将NV21转换为I420的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆