Sto tentando di aggiungere una funzione di acquisizione video a un'app di AR. In pratica, registra ciò che accade sullo schermo e lo salva come video (consentendo all'utente di condividerlo). L'APP AR è scritta con l'SDK Vuforia-Unity. Abbiamo raggiunto con successo questo sulla piattaforma iOS.Acquisizione video su AR (Vuforia) con unità nella piattaforma Android
Tuttavia, abbiamo grandi difficoltà a fare la stessa cosa sulla piattaforma Android. (Speriamo di raggiungere questo obiettivo con il radicamento del dispositivo)
Il seguente è il nostro progresso:
La fotocamera è ocuppied dal programma Vuforia, non posso accedere al flusso video.
Ho provato a catturare uno screeshot di ciascun fotogramma e quindi li unisco ad alcuni output video; ma il framerate è eccezionalmente scarso (meno di 1 fps). Ci vogliono 700ms per catturare una schermata.
Sto pensando dalla direzione sbagliata? Qualsiasi aiuto sarà profondamente apprezzato! Mille grazie! Isaac
Quello che segue è il mio codice di prova:
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();
}
}
per caso hai trovato la soluzione :) –
non ancora .....>< – user2542563
Qualche progresso? Sto facendo esattamente la stessa cosa senza fortuna fino ad ora. – vmachacek