Android – how to get frames from video file?-ThrowExceptions

Exception or error:

I want to extract frames from video file stored on the device. Every solution i found is to use FFmpegMediaMetadataRetriever or MediaMetadaraRetriever, but as I wrote here it’s not working for me. Is there any other way to extract frames from video?

How to solve:

I admit I haven’t used this method for a while, but if it still works with the current Android API, it should do the trick.

Please let me know if it still works. If not – I will delete this answer.

public static Bitmap getVideoFrame(Context context, Uri uri, long time) {

    Bitmap bitmap = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();

    try {

        retriever.setDataSource(context, uri);
        bitmap = retriever.getFrameAtTime(time);

    } catch (RuntimeException ex) {
        ex.printStackTrace();

    } finally {

        try {

            retriever.release();

        } catch (RuntimeException ex) {
            ex.printStackTrace();
        }
    }

    return bitmap;
}

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *