2

I am trying to extract Thumbnail images from a Video file, the use case is that I want a Bitmap image for every other second of the video, I tried using MediaMetadataRetriever, but the problem is it returns same frames, no matter what the time is.

This is the code which I had tried

MediaMetadataRetriever retriever = new MediaMetadataRetriever(); 
            retriever.setDataSource(PATH); 
             for(int i = 0; i< 10 ;i++) {

                Bitmap bmp = retriever.getFrameAtTime(i * 1000, MediaMetadataRetriever.OPTION_CLOSEST);
                imgList.add(bmp);
                System.out.println(imgList.size());

            }

Is there any other feasible solution to get Frames periodically?

Arif Nadeem
  • 8,524
  • 7
  • 47
  • 78

1 Answers1

3

Time for the MediaMetadataRetriever is specified in microseconds.

To get the frame at 2 seconds you have to call:

Bitmap bmp = retriever.getFrameAtTime(2 * 1000000, MediaMetadataRetriever.OPTION_CLOSEST);

I've found that MediaMetadataRetriever returns the same frame for a whole second regardless of this very precise timestamp, but for your requirements it should work.

Christo
  • 182
  • 3
  • 8