Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to Generate a thumbnail from a video url in android

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.

like image 469
DKV Avatar asked Apr 09 '14 06:04

DKV


People also ask

How do I get the thumbnail of a 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.


Video Answer


2 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.

like image 72
KishuDroid Avatar answered Oct 05 '22 23:10

KishuDroid


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 
like image 23
Manohar Avatar answered Oct 06 '22 00:10

Manohar