My advice: use MediaMetadataRetriever and call the getFrameAtTime() method to retrieve the frames you want to extract:
// Get your video file File myVideo = new File (Environment.getExternalStorageDirectory().getAbsolutePath(), "YOUR_FILE.mp4"); // URI to your video file Uri myVideoUri = Uri.parse(myVideo.toString()); // MediaMetadataRetriever instance MediaMetadataRetriever mmRetriever = new MediaMetadataRetriever(); mmRetriever.setDataSource(myVideo.getAbsolutePath()); // Array list to hold your frames ArrayList<Bitmap> frames = new ArrayList<Bitmap>(); //Create a new Media Player MediaPlayer mp = MediaPlayer.create(getBaseContext(), myVideoUri); // Some kind of iteration to retrieve the frames and add it to Array list Bitmap bitmap = mmRetriever.getFrameAtTime(TIME IN MICROSECONDS); frames.add(bitmap);
And then programmatically create an Animated Animation :
AnimationDrawable animatedGIF = new AnimationDrawable(); animationDrawable.addFrame("FIRST FRAME", 50); animationDrawable.addFrame("SECOND FRAME", 50); ... animationDrawable.addFrame("LAST FRAME ", 50);
source share