android nv21 nv12,android - 将NV21转换为NV12并旋转90度通过libyuv? - 堆栈内存溢出
我正在開(kāi)發(fā)一個(gè)Android Camera應(yīng)用程序。 當(dāng)我處理框架時(shí),遇到了一些麻煩。
在相機(jī)的onPreviewFrame(字節(jié)[]數(shù)據(jù),攝像頭攝像頭)功能,我設(shè)置數(shù)據(jù)的格式是NV21 fromat,由于NV21是支持所有的Android設(shè)備。
當(dāng)我使用MediaCodec編碼幀時(shí),KEY_COLOR_FORMAT為COLOR_FormatYUV420SemiPlanar( NV12 )。
所以我需要將NV21轉(zhuǎn)換為NV12。
而且,框架旋轉(zhuǎn)-90度,我要旋轉(zhuǎn)回來(lái),意味著旋轉(zhuǎn)90度。
我通過(guò)使用java做到了:
// 1. rotate 90 degree clockwise
// 2. convert NV21 to NV12
private byte[] rotateYUV420SemiPlannerFrame(byte[] input, int width, int height) {
//from:https://github.com/upyun/android-push-sdk/blob/7d74e3c941bbede0b6f9f588b1d4e7926a5f2733/uppush/src/main/java/com/upyun/hardware/VideoEncoder.java
int frameSize = width * height;
byte[] output = new byte[frameSize * 3 / 2];
int i = 0;
for (int col = 0; col < width; col++) {
for (int row = height - 1; row >= 0; row--) {
output[i++] = input[width * row + col]; // Y
}
}
i = 0;
for (int col = 0; col < width / 2; col++) {
for (int row = height / 2 - 1; row >= 0; row--) {
int i2 = i * 2;
int fwrc2 = frameSize + width * row + col * 2;
output[frameSize + i2 + 1] = input[fwrc2]; // Cb (U)
output[frameSize + i2] = input[fwrc2 + 1]; // Cr (V)
i++;
}
}
return output;
}
該功能運(yùn)行良好,但耗時(shí)較長(zhǎng) ,超過(guò)50ms。
據(jù)我所知, libyuv處理YUV img更快,我想在我的android Camera應(yīng)用程序中使用它。
在libyuv中,我發(fā)現(xiàn)三個(gè)功能可能會(huì)有所幫助:
// Convert NV21 to I420.
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);
// Rotate I420 frame.
LIBYUV_API
int I420Rotate(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v,
int src_width, int src_height, enum RotationMode mode);
LIBYUV_API
int I420ToNV12(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
uint8* dst_y, int dst_stride_y,
uint8* dst_uv, int dst_stride_uv,
int width, int height);
使用這些功能,可能會(huì)工作。 但是轉(zhuǎn)換和旋轉(zhuǎn)可能會(huì)花費(fèi)更多時(shí)間(我想..)。
有什么辦法可以通過(guò)減少功能來(lái)達(dá)到我的目標(biāo)? 謝謝。
我還在這里找到了一些答案,不是我想要的。
總結(jié)
以上是生活随笔為你收集整理的android nv21 nv12,android - 将NV21转换为NV12并旋转90度通过libyuv? - 堆栈内存溢出的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Mentor.Graphics.Desi
- 下一篇: 数据分析学习总结笔记12:空间自相关——