I am working on a video app. I am streaming a video from server link , is it possible for me to generate a video thumbnail from the URL without downloading the video.
-
is it a youtube video? – Karthik Jul 04 '15 at 12:02
9 Answers
Without downloading video you can generate thumbnail from below code:
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);
// 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;
}
NOTE : Video is stored as Intra and non Intra (Picture frames) getFrameAtTime will return the closest non- Intra frame as Bitmap. So basically it won't download the entire video.

- 8,954
- 10
- 58
- 80

- 5,411
- 4
- 30
- 47
-
@OmarRehman: Your welcome. I have checked it and didn't get any delay. – KishuDroid Feb 08 '16 at 05:27
-
-
-
If getFrameAtTime() downloads the entire video it defeats the purpose a little. I want to know if that method downloads the entire video. If so I would rather just download the video. – lostintranslation Feb 24 '16 at 04:03
-
1@lostintranslation Video is stored as Intra and non Intra (Picture frames) getFrameAtTime will return the closest non- Intra frame as Bitmap. So basically it won't download the entire video. Hope you got your answer. – KishuDroid Feb 24 '16 at 04:07
-
Hello guys can you please help me on this , how can i attach a thumbnail on an ImageView ,coz i tried to replace mediaMetadataRetriever with an ImageView but it didnt work – Lutaaya Huzaifah Idris Nov 29 '16 at 08:59
-
@LutaayaHuzaifahIdris : you will get bitmap after passing video url in this method and can set that bitmap in your imageview. – KishuDroid Nov 30 '16 at 08:51
-
2Thanks @KishuDroid , i did it , but the challenge with this , it's takes too much time to load on Lollipop 5 , isn't there any cool library to load URL videos into the RecyclerView – Lutaaya Huzaifah Idris Nov 30 '16 at 13:23
-
1@LutaayaHuzaifahIdris: If you are getting videos link from server then you can also ask for thumbnail image of video from the server and then you can load it into the recyclerview. This is the easy and fast way to load videos. – KishuDroid Dec 01 '16 at 03:56
-
-
-
-
1@KishuDroid I use your code..It work fines..But have 1 problem,when the video is short,sometime the video is short,then the thumbnails does not come out..just blank – ken Nov 10 '17 at 08:51
I tried this with glide and it worked , Glide version 4.3.1
GlideApp.with(context)
.asBitmap()
.load(FILE_URL)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(iv_picture);
Edit : Glide was working slow for me
The Top answer was not giving result for some videos , here is how i did it
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//give YourVideoUrl below
retriever.setDataSource("YourVideoUrl", new HashMap<String, String>());
// this gets frame at 2nd second
Bitmap image = retriever.getFrameAtTime(2000000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
//use this bitmap image

- 22,116
- 9
- 108
- 144
-
I think it is needed to release MediaMetadataRetriver after done. -> retriever.release() – Hadi Ahmadi Apr 20 '21 at 11:31
-
The second solution of your is working... thanks and keep it up – Pir Fahim Shah Nov 17 '21 at 12:35
It is not possible to create thumbnail from steaming link, you have to show it from server. Better upload a thumbnail along the video. Use the below code to generate thumbnail
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail("picturePath", MediaStore.Video.Thumbnails.MINI_KIND);
Here's your link:
- Android: Is it possible to display video thumbnails?
- http://developer.android.com/reference/android/media/ThumbnailUtils.html
In my opinion, Server side should create thumbnail from a video and transfer thumbnail video images through your service.
-
hi i am able to create the thumbnail from the recorded video.But while streaming is it possible ? – DKV Apr 09 '14 at 09:14
You can generate Thumbnail from server URL like given below
- Add Glide Library then use like this following
RequestOptions requestOptions = new RequestOptions(); requestOptions.isMemoryCacheable(); requestOptions.override(70,70); Glide.with(context).setDefaultRequestOptions(requestOptions).load(model.getMediaURL()).into(myViewHolder.imageView);

- 202
- 2
- 3
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail("VIDEO FILE ADDRESS", MediaStore.Video.Thumbnails.MINI_KIND);

- 18,333
- 31
- 67
- 74

- 51
- 6
This method will give you thumbnails of all the video files in your phone... feel free to ask questions
public static Bitmap[] getThumbnail(Context context){
Uri uri=MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection=new String[] { MediaStore.Video.Thumbnails._ID };
Cursor ca = context.getContentResolver().query(uri, projection, null, null, null);
Bitmap[] b=new Bitmap[ca.getCount()];
int i=0;
ca.moveToFirst();
while(i<ca.getCount()) {
int id = ca.getInt(ca.getColumnIndex(MediaStore.Video.Thumbnails._ID));
b[i++]=MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(),id, MediaStore.Images.Thumbnails.MINI_KIND, null );
ca.moveToNext();
}
ca.close();
return b;
}

- 15,179
- 13
- 69
- 123

- 51
- 6
Here is the best solution
"https://img.youtube.com/vi/" + videoID + "/0.jpg"
Here videoID you get from youtube Url.

- 186
- 1
- 12
We fetch all video in Android Phone. http://sunilkmrnishad.blogspot.in/2017/03/read-files-apps-photos-media-from.html
public class ThumbnailExtract extends AsyncTask<String, long[], Bitmap> {
private final String videoUrl;
private final ImageView mThumbnail;
private final boolean mIsVideo;
private MediaMetadataRetriever mmr;
public ThumbnailExtract(String videoLocalUrl, ImageView thumbnail, boolean isVideo) {
this.videoUrl = videoLocalUrl;
mThumbnail = thumbnail;
mIsVideo = isVideo;
if (!isVideo) {
mmr = new MediaMetadataRetriever();
}
}
@Override
protected Bitmap doInBackground(String... params) {
if (!mIsVideo) {
return getBitmap(videoUrl);
} else {
return ThumbnailUtils.createVideoThumbnail(videoUrl,
MediaStore.Images.Thumbnails.MINI_KIND);
}
}
@Override
protected void onPostExecute(Bitmap thumb) {
if (thumb != null) {
mThumbnail.setImageBitmap(thumb);
}
}
private Bitmap getBitmap(String fileUrl) {
mmr.setDataSource(fileUrl);
byte[] data = mmr.getEmbeddedPicture();
Bitmap bitmap = null;
// convert the byte array to a bitmap
if (data != null) {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
}
return bitmap != null ? ScalingUtilities.createScaledBitmap(bitmap, 40, 40, ScalingUtilities.ScalingLogic.FIT) : bitmap;
}
}