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.
You can take a screenshot from your video that best explains its contents, or you can use a tool like Photoshop or Canva to overlay text or icons on the image. To make a screen capture on a PC, use the Windows Snipping Tool. For Mac users, hit Command+Shift+4 to select the part of your screen you want to capture.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With