I want to create a thumbnail of a video from the SD card path. How can I do that?
3 Answers
You can use ThumbnailUtils
class to get Video thumbnail of Video file.
createVideoThumbnail()
is method which return Bitmap (thumbnail) of video from video file path.
From Android Docs:
public static Bitmap createVideoThumbnail (String filePath, int kind)
Create a video thumbnail for a video. May return null if the video is corrupt or the format is not supported.
You can create VideoThumbnail from sdcard path like this.
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);
Using ThumbnailUtils
, you can create thumbnail of two types.
MediaStore.Images.Thumbnails.MICRO_KIND
type will generate thumbnail of size 96 x 96.MediaStore.Images.Thumbnails.MINI_KIND
type will generate thumbnail of size 512 x 384.
I hope it helps!

- 12,801
- 5
- 53
- 78
-
No it does not. it only works with video files that are in storage – Rajesh Jadav Dec 15 '15 at 04:20
-
I have tried it, but it didn't work for the videos that are on SD Card (External Storage) on Android 5.0+. It returned null bitmap – Dante May 23 '16 at 14:18
-
@Riten how are you getting filepath and on which andorid os? – Rajesh Jadav Dec 01 '16 at 12:29
-
How can I set the filepath from a video on the raw folder? – FeanDoe Jul 31 '17 at 15:53
-
If you're getting null bitmap then try to run it in real device and not in emulator. I wasted hours in emulator testing. – Kishan Solanki Jan 09 '18 at 11:44
-
Chances of getting out of memory errors are high on this. – krisDrOid Mar 16 '18 at 21:56
-
how about the .flv or .avi file? – Tushar Monirul Oct 03 '18 at 21:01
-
doen't help in my case :( – swati vishnoi Sep 23 '20 at 07:01
If you are directly creating thumbnails as follows
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
MediaStore.Images.Thumbnails.MINI_KIND);
Then there is a problem with this method if your are creating thumbnails for large video set(for large number of videos). the application will freeze until all the thumbnails are loaded because all the process are executing in the main thread.
Use SuziLoader
This loader will load the thumbnails for the videos which is locally stored on your filesystem in background.
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/video.mp4";
ImageView mThumbnail = (ImageView) findViewById(R.id.thumbnail);
SuziLoader loader = new SuziLoader(); //Create it for once
loader.with(MainActivity.this) //Context
.load(path) //Video path
.into(mThumbnail) // imageview to load the thumbnail
.type("mini") // mini or micro
.show(); // to show the thumbnail
To get this dependency use the following steps
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.sushinpv:SuziVideoThumbnailLoader:0.1.0'
}
ADD READ EXTERNAL STORAGE Permission in manifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

- 1,826
- 3
- 22
- 36
Please check my code hope it will help you
/**
* Retrieve video frame image from given video path
*
* @param p_videoPath
* the video file path
*
* @return Bitmap - the bitmap is video frame image
*
* @throws Throwable
*/
@SuppressLint("NewApi")
public static Bitmap retriveVideoFrameFromVideo(String p_videoPath)
throws Throwable
{
Bitmap m_bitmap = null;
MediaMetadataRetriever m_mediaMetadataRetriever = null;
try
{
m_mediaMetadataRetriever = new MediaMetadataRetriever();
m_mediaMetadataRetriever.setDataSource(p_videoPath);
m_bitmap = m_mediaMetadataRetriever.getFrameAtTime();
}
catch (Exception m_e)
{
throw new Throwable(
"Exception in retriveVideoFrameFromVideo(String p_videoPath)"
+ m_e.getMessage());
}
finally
{
if (m_mediaMetadataRetriever != null)
{
m_mediaMetadataRetriever.release();
}
}
return m_bitmap;
}
Modify above method according to your need