Skip to content

Instantly share code, notes, and snippets.

@arthtilva
Created January 26, 2017 10:24
Show Gist options
  • Save arthtilva/e02821dbe7f0e9e82644f9a0445230f7 to your computer and use it in GitHub Desktop.
Save arthtilva/e02821dbe7f0e9e82644f9a0445230f7 to your computer and use it in GitHub Desktop.
Create image/thumbnail from Video.
public static Bitmap retriveVideoFrameFromVideo(String videoPath) throws Throwable {
Bitmap bitmap = null;
MediaMetadataRetriever mediaMetadataRetriever = null;
try {
mediaMetadataRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
else
mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime();
} catch (Exception e) {
e.printStackTrace();
throw new Throwable(
"Exception in retriveVideoFrameFromVideo(String videoPath)"
+ e.getMessage());
} finally {
if (mediaMetadataRetriever != null) {
mediaMetadataRetriever.release();
}
}
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment