【发布时间】:2016-04-05 23:07:01
【问题描述】:
我有一个 mp4 文件列表,我需要为每个文件提取缩略图。
缩略图标准:
缩略图必须是 Base64 格式
缩略图具有特定大小,将作为方法参数提供
必须从文件中间的帧中提取(例如,如果视频时长为 10 秒,则缩略图必须从第 5 秒的帧中提取。
1 和 2 目前已实现,但我不确定如何执行 3。
这是我的代码:
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;
}
}
【问题讨论】: