0

I am trying to get a frame from the video (thumbnail) and convert it to base64. I have used the following code but sometimes it doesn't work:

        Uri selectedVideo = Uri.parse(intent.getStringExtra("trimmedVideo"));

        MediaMetadataRetriever mMMR = new MediaMetadataRetriever();
        mMMR.setDataSource(this, selectedVideo);
        Bitmap thumbnail = mMMR.getFrameAtTime();
        Log.d(Global.getTag(), "thumbnail: "+thumbnail);

Also I get this error in logcast:

E/MediaMetadataRetrieverJNI: getFrameAtTime: videoFrame is a NULL pointer

And thumbnail is null. Thanks in advance.

Note: I also try to use the next code but it doesn't work.

Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND);
Ela96
  • 35
  • 6

1 Answers1

0

Ref: https://stackoverflow.com/a/32517167/13533028

1st Method

Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND);

The Thumbnails part decides the type of thumbnail it will be.(big or small)

2nd Method

https://github.com/sushinpv/SuziVideoThumbnailLoader

This is a library which will make it easier for you to implement

3rd Method

Using Glide Library

RequestOptions requestOptions = new RequestOptions();
 Glide.with(getContext())
      .load("video_url")
      .apply(requestOptions)
      .thumbnail(Glide.with(getContext()).load("video_url"))
      .into("yourimageview");
Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31
  • I try with that but it returns null (1) and I need to have the thumbnail to convert it to base64, so I can't use 2. – Ela96 Apr 23 '21 at 17:27
  • Yes, and requested for API >= 23, but for now I'm using a cellphone with API 22 so that doesn't matter. Also the crash happens sometimes not all the time, I read that MediaMetadataRetriever sometimes doesn't work. – Ela96 Apr 23 '21 at 17:37
  • Added another implementation using glide library – Narendra_Nath Apr 23 '21 at 19:29
  • I can't use Glide because I need the thumbnail to load it to ImageView BUT also I need to convert that thumbnail it to base64, – Ela96 Apr 23 '21 at 19:31