I have a list of mp4 files that i need to extract a thumbnail for each one.
Thumbnail criteria:
The thumbnail must be in Base64 format
The thumbnail has a specific size which will be provided as a method parameter
It must be extracted from the frame in the middle of the file (e.g. if the video duration is 10s then the thumbnail must be from the frame in 5th second.
1 and 2 are currently achieved but I'm not sure how to do 3.
This is my code:
public static String getVideoDrawable(String path, int height, int width) throws OutOfMemoryError{
try {
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(path, android.provider.MediaStore.Images.Thumbnails.MINI_KIND);
bitmap = Bitmap.createScaledBitmap(bitmap, height, width, false);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
return Base64.encodeToString(byteArray, Base64.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}