Search code examples
androidandroid-mediaplayer

How to get the frame from video file in android


The MediaMetadataRetriever.getFrameAtTime() always returns same frames when ever call. Have a look my code

private ArrayList<Bitmap> getFrames(String path){
    try {
        ArrayList<Bitmap> bArray = new ArrayList<Bitmap>();
        bArray.clear();
        MediaMetadataRetriever mRetriever = new MediaMetadataRetriever();
        mRetriever.setDataSource(getDataSource(path));

        for (int i = 3000; i <60000; i=i+5000) {
            bArray.add(mRetriever.getFrameAtTime(i, MediaMetadataRetriever.OPTION_CLOSEST_SYNC));

        }

        return bArray;
    } catch (Exception e) {
        // TODO: handle exception

        return null;

    }
}

This method always return same frames


Solution

  • You are going to have to use something like FFMPEG to fetch the frames.

    You will have to use the NDK, and compile FFMPEG for Android; unfortunately it's not going to be very easy.

    A couple of starting points:

    http://ffmpeg.org/

    ffmpeg for a android (using tutorial: "ffmpeg and Android.mk")

    Good luck!