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

DKV picture DKV · Apr 9, 2014 · Viewed 38.4k times · Source

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.

Answer

KishuDroid picture KishuDroid · Sep 21, 2015

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.