AR(Vuforia)上的视频捕捉在Android平台上统一

时间:2013-07-02 12:44:50

标签: android video unity3d augmented-reality vuforia

我正在尝试为AR应用添加视频捕获功能。 基本上记录屏幕上发生的事情,并将其保存为视频(允许用户共享)。 AR APP使用Vuforia-Unity SDK编写。 我们已经在iOS平台上成功实现了这一目标。

然而,在Android平台上做同样的事情我们遇到了很大的困难。 (我们希望通过设备生根来实现这一目标)

以下是我们的进展:

  1. Vuforia程序使相机失灵,我无法访问视频流。

  2. 我尝试捕捉每帧的screeshot,然后将它们组合成一些视频输出;但帧率很差(小于1 fps)。拍摄屏幕截图需要700毫秒。

  3. 我是从错误的方向思考的吗?任何帮助将深表感谢! 非常感谢! 艾萨克

    以下是我的测试代码:

    public void acquireScreenshot() {
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager WM = (WindowManager) MainActivity.this.getSystemService(Context.WINDOW_SERVICE);
        Display display = WM.getDefaultDisplay();
        display.getMetrics(metrics);
        int height = metrics.heightPixels; // screen height
        int width = metrics.widthPixels; // screen width
        int pixelformat = display.getPixelFormat();
        PixelFormat localPixelFormat1 = new PixelFormat();
        PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
        int deepth = localPixelFormat1.bytesPerPixel;
    
        byte[] arrayOfByte = new byte[height* width* deepth];
        long tmp = System.currentTimeMillis();
        try {
            for(int i = 0 ; i < 10 ; i++){
                InputStream localInputStream = readAsRoot();
                DataInputStream localDataInputStream = new DataInputStream(
                        localInputStream);
                android.util.Log.e("mytest", "-----read start-------");
                localDataInputStream.readFully(arrayOfByte);
                android.util.Log.e("mytest", "-----read end-------time = "  + (System.currentTimeMillis() -tmp ));
                localInputStream.close();
    
                File mid = new File("/mnt/sdcard/AAA");
    
                if(!mid.exists()){
                    mid.mkdir();
                }
    
                FileOutputStream out = new FileOutputStream(new File(
                        "/mnt/sdcard/AAA/"+System.currentTimeMillis()+".png"));  
                int[] tmpColor = new int[width * height];
                int r, g, b;
                tmp = System.currentTimeMillis();
                android.util.Log.e("mytest", "-----bitmap start-------");
                for (int j = 0; j < width * height * deepth; j+=deepth) {
                    b = arrayOfByte[j]&0xff;
                    g = arrayOfByte[j+1]&0xff;
                    r = arrayOfByte[j+2]&0xff;
                    tmpColor[j/deepth] = (r << 16) | (g << 8) | b |(0xff000000);
                }
                Bitmap tmpMap = Bitmap.createBitmap(tmpColor, width, height,
                        Bitmap.Config.ARGB_8888);
                android.util.Log.e("mytest", "-----bitmap end-------time = "  + (System.currentTimeMillis() -tmp ));
    
                tmp = System.currentTimeMillis();
                android.util.Log.e("mytest", "-----compress start-------");
                tmpMap.compress(Bitmap.CompressFormat.PNG, 100, out);
                android.util.Log.e("mytest", "-----compress end-------time = "  + (System.currentTimeMillis() -tmp ));
                out.close();
                Thread.sleep(40);
            }
    
    
        } catch (Exception e) {
            android.util.Log.e("mytest", "Exception");
            e.printStackTrace();
        }
    
    }
    

1 个答案:

答案 0 :(得分:0)

我们曾经使用过一些英特尔插件来实现相机记录。

Video Capturing for Unity3d* Applications on Android*

实施起来非常简单。希望你能发现它们有用。