Is it possible to convert recorded video into GIF in Android programmatically? Can you help me with some sniped code or tell me how to do it?
My advice would be to use MediaMetadataRetriever and call 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 create a Drawable Animation programmatically:
AnimationDrawable animatedGIF = new AnimationDrawable();
animationDrawable.addFrame("FIRST FRAME", 50);
animationDrawable.addFrame("SECOND FRAME", 50);
...
animationDrawable.addFrame("LAST FRAME ", 50);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With