久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 Android 中的視頻圖像中獲取幀

Getting frames from Video Image in Android(從 Android 中的視頻圖像中獲取幀)
本文介紹了從 Android 中的視頻圖像中獲取幀的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經實現了一個在屏幕上顯示相機圖片的簡單應用程序.我現在喜歡做的是抓取一個幀并將其作為位圖處理.據我所知,這并不是一件容易的事.

I've implemented a simple application which shows the camera picture on the screen. What I like to do now is grab a single frame and process it as bitmap. From what I could find out to this point it is not an easy thing to do.

我嘗試使用 onPreviewFrame 方法將當前幀作為字節數組獲取,并嘗試使用 BitmapFactory 類對其進行解碼,但它返回 null.幀的格式是無標題的 YUV,可以轉換為位圖,但在手機上花費的時間太長.此外,我還了解到 onPreviewFrame 方法對運行時有限制,如果耗時過長,應用程序可能會崩潰.

I've tried using the onPreviewFrame method with which you get the current frame as a byte array and tried to decode it with the BitmapFactory class but it returns null. The format of the frame is a headerless YUV which could be translated to bitmap but it takes too long on a phone. Also I've read that the onPreviewFrame method has contraints on the runtime, if it takes too long the application could crash.

那么正確的方法是什么?

So what is the right way to do this?

推薦答案

在 API 17+ 中,您可以使用 'ScriptIntrinsicYuvToRGB' RenderScript 從 NV21 轉換為 RGBA888.這使您無需手動編碼/解碼幀即可輕松處理預覽幀:

In API 17+, you can do conversion to RGBA888 from NV21 with the 'ScriptIntrinsicYuvToRGB' RenderScript. This allows you to easily process preview frames without manually encoding/decoding frames:

@Override 
public void onPreviewFrame(byte[] data, Camera camera) { 
   Bitmap bitmap = Bitmap.createBitmap(r.width(), r.height(), Bitmap.Config.ARGB_8888);
    Allocation bmData = renderScriptNV21ToRGBA888(
        mContext,
        r.width(),
        r.height(),
        data);
    bmData.copyTo(bitmap);
}

public Allocation renderScriptNV21ToRGBA888(Context context, int width, int height, byte[] nv21) {
  RenderScript rs = RenderScript.create(context);
  ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));

  Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(nv21.length);
  Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);

  Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height);
  Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);

  in.copyFrom(nv21);

  yuvToRgbIntrinsic.setInput(in);
  yuvToRgbIntrinsic.forEach(out);
  return out;
}

這篇關于從 Android 中的視頻圖像中獲取幀的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why does the android emulator camera stop unexpectedly?(為什么android模擬器相機會意外停止?)
Android camera , onPictureTaken(byte[] imgData, Camera camera) method amp; PictureCallback never called(Android camera , onPictureTaken(byte[] imgData, Camera camera) 方法 amp;PictureCallback 從未調用過) - IT屋-程序員軟件開發技
Understanding the libGDX Projection Matrix(了解 libGDX 投影矩陣)
QR code reading with camera - Android(使用相機讀取二維碼 - Android)
IP camera with OpenCv in Java(Java中帶有OpenCv的IP攝像頭)
Android mock Camera(Android 模擬相機)
主站蜘蛛池模板: 欧美日在线 | 久久久激情 | 国产亚韩 | 中文字幕日韩欧美一区二区三区 | 91啪影院| www成年人视频 | 一区二区三区高清不卡 | www.久久 | 国产精品成人在线 | 亚洲精品视频一区二区三区 | 婷婷激情综合 | 一级一片在线观看 | 久久99蜜桃综合影院免费观看 | 亚洲永久入口 | 亚洲精品一区二区三区在线观看 | 亚洲综合精品 | 欧美中文在线 | 可以免费观看的av片 | 欧美综合在线视频 | 亚洲成人国产精品 | 日韩精品一区二区三区高清免费 | 成人在线不卡 | 久久久久久网 | 亚洲一区二区在线播放 | 手机av在线 | 美女在线一区二区 | 91婷婷韩国欧美一区二区 | 欧美精品久久久久久久久老牛影院 | 国产精品高潮呻吟久久av野狼 | 久久国产亚洲 | 国产探花在线精品一区二区 | 精品国产区 | 一区二区三区电影在线观看 | 欧美一区二区三区在线观看 | 久久毛片| 九九亚洲 | 欧美精品在欧美一区二区少妇 | 五月婷婷激情 | 中文在线一区 | 亚洲福利一区 | 中文字幕一区二区三区在线观看 |