Example to retrieve frame in video:
package com.example.androidmediametadataretriever;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.widget.ImageView;
import android.app.Activity;
public class MainActivity extends Activity {
String uri = "/storage/sdcard0/DCIM/100MEDIA/VIDEO0007.mp4";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView capturedImageView = (ImageView)findViewById(R.id.capturedimage);
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(uri);
Bitmap bmFrame = mediaMetadataRetriever.getFrameAtTime(5000000); //unit in microsecond
capturedImageView.setImageBitmap(bmFrame);
}
}
Next:
- Get the current frame in VideoView using MediaMetadataRetriever
Updated@2014-12-29:
Permission of "android.permission.READ_EXTERNAL_STORAGE" is needed, otherwise MediaMetadataRetriever.setDataSource() will throw IllegalArgumentException.
Read: MediaMetadataRetriever: IllegalArgumentException thrown from setDataSource()
I am getting only one frame/ current frame from mediametadataretriever.
ReplyDeleteI want to take all frames from a video which has been stored in sdcard.. How to do it..
How can I save that bitmap to sdcard?
ReplyDeletehello Osc,
ReplyDeleteyou have a bitmap, so you can save bitmap to sdcard.
Bitmap bmFrame = mediaMetadataRetriever.getFrameAtTime(5000000);
ReplyDeletei am getting null value in bmFrame.. so what i do
hello sugumar.p sugu,
ReplyDeletegetFrameAtTime() return null means such a frame cannot be retrieved.
hello, i tried the above code in android 4.0 (icecream sandwich) but it throwing fatal exception, can u pls help me
ReplyDeletehello Ankita A,
ReplyDeleteIs it IllegalArgumentException thrown from the code mediaMetadataRetriever.setDataSource(uri)?
If yes, please read my update: MediaMetadataRetriever: IllegalArgumentException thrown from setDataSource().
thank you, its working now, but am getting only one frame.i want to extract all frames. how to do it?
ReplyDeleteDoes anyone get the solution for extracting all frames from video in android??
ReplyDelete