List of usage examples for android.media MediaMetadataRetriever OPTION_NEXT_SYNC
int OPTION_NEXT_SYNC
To view the source code for android.media MediaMetadataRetriever OPTION_NEXT_SYNC.
Click Source Link
From source file:com.univpm.s1055802.faceplusplustester.Detect.AcquireVideo.java
/** * Estrae un frame per ogni secondo del video e li salva sul dispositivo * @param uri uri della cartella dove salvare i frames *///from w w w.j a v a2 s .co m private void captureFrames(Uri uri) { String filePath = FileUtils.getPath(getApplicationContext(), uri); File video = new File(filePath); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(filePath); double duration = Double .parseDouble(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); Log.v("duration", String.valueOf(duration)); int timeSkip = 1000000; for (int i = 0; i < duration * 1000; i = i + timeSkip) { File img = null; try { img = new File(framesDir, "Frame_" + String.valueOf(i / timeSkip) + ".jpg"); OutputStream fOut = null; fOut = new FileOutputStream(img); Bitmap imgBmp = retriever.getFrameAtTime(i, MediaMetadataRetriever.OPTION_NEXT_SYNC); imgBmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut); fOut.flush(); fOut.close(); } catch (IOException e) { e.printStackTrace(); } } } catch (IllegalArgumentException ex) { ex.printStackTrace(); } catch (RuntimeException ex) { ex.printStackTrace(); } finally { try { retriever.release(); } catch (RuntimeException ex) { } } }