Extract bitmap from video in android

I am trying to extract all frames from a video.
Following the code, I want to get the first 30 frames of the video, but I only got the first frame 30 times.

private ArrayList<Bitmap> getFrames(String path) { try { ArrayList<Bitmap> bArray = new ArrayList<Bitmap>(); bArray.clear(); MediaMetadataRetriever mRetriever = new MediaMetadataRetriever(); mRetriever.setDataSource("/sdcard/myvideo.mp4"); for (int i = 0; i < 30; i++) { bArray.add(mRetriever.getFrameAtTime(1000*i, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)); } return bArray; } catch (Exception e) { return null; } } 

Now, how can I get all the frames from the video?

+8
android video bitmap media
source share
2 answers

Support for video in the Android SDK is limited, and frame extraction for H264 video is only possible for key frames. To extract an arbitrary frame, you need a library, for example FFmpegMediaMetadataRetriever , which uses its own code to extract data from the video. It is very fast, comes with pre-compiled binaries (for ARM and x86), so you do not need to delve into C ++ and make files, it is licensed under Apache 2.0 and comes with a demo Android application.

There is also a pure Java library, JCodec , but it is slower, and when I used it last year, the frame extraction colors were distorted.

+2
source share

getFrameAt get the data in milliseconds , but you increase the .001 miliseconds in for loop.

  for(int i=1000000;i<millis*1000;i+=1000000) // for incrementing 1s use 1000 { bArray.add(mRetriever.getFrameAtTime(i, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)); } 

change it as above. Above is a model for creating what you want. I also answered it here

0
source share

All Articles