android nv21 nv12,android - 将NV21转换为NV12并旋转90度通过libyuv? - 堆栈内存溢出
我正在開發一個Android Camera應用程序。 當我處理框架時,遇到了一些麻煩。
在相機的onPreviewFrame(字節[]數據,攝像頭攝像頭)功能,我設置數據的格式是NV21 fromat,由于NV21是支持所有的Android設備。
當我使用MediaCodec編碼幀時,KEY_COLOR_FORMAT為COLOR_FormatYUV420SemiPlanar( NV12 )。
所以我需要將NV21轉換為NV12。
而且,框架旋轉-90度,我要旋轉回來,意味著旋轉90度。
我通過使用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;
}
該功能運行良好,但耗時較長 ,超過50ms。
據我所知, libyuv處理YUV img更快,我想在我的android Camera應用程序中使用它。
在libyuv中,我發現三個功能可能會有所幫助:
// 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);
使用這些功能,可能會工作。 但是轉換和旋轉可能會花費更多時間(我想..)。
有什么辦法可以通過減少功能來達到我的目標? 謝謝。
我還在這里找到了一些答案,不是我想要的。
總結
以上是生活随笔為你收集整理的android nv21 nv12,android - 将NV21转换为NV12并旋转90度通过libyuv? - 堆栈内存溢出的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mentor.Graphics.Desi
- 下一篇: 数据分析学习总结笔记12:空间自相关——