Created
January 26, 2017 10:24
-
-
Save arthtilva/e02821dbe7f0e9e82644f9a0445230f7 to your computer and use it in GitHub Desktop.
Create image/thumbnail from Video.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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