rosu alin
rosu alin

Reputation: 5830

retriever.getFrameAtTime is not accurate, how can i get screenshot of video?

This is the function i am using:

public Bitmap getVideoFrame(String FD, long time) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(FD);
        return retriever.getFrameAtTime(time * 1000, MediaMetadataRetriever.OPTION_CLOSEST);
    } catch (IllegalArgumentException ex) {
        ex.printStackTrace();
    } catch (RuntimeException ex) {
        ex.printStackTrace();
    } finally {
        try {
            retriever.release();
        } catch (RuntimeException ex) {
        }
    }
    return null;
}

where: FD is the path of the video time = videoview.getCurrentPosition();

The problem is that this function does not get the exact frame i need to get. on a longer video (20 min) it will be more accurate than in a short video (10-20 seconds). Is there something i am missing, if not, what could I use instead of the retriever?

Upvotes: 2

Views: 3857

Answers (5)

VIISHRUT MAVANII
VIISHRUT MAVANII

Reputation: 12678

Yes, I Agree retriever.getFrameAtTime is not accurate.

An alternative solution to replace the getFrameAt method of Android MediaMetadataRetriever. AV_FrameCapture uses MediaCodec to decode the video frame and use OpenGL to convert the video frame as RGB Bitmap. As Android MediaMetadataRetriever does not guarantee to return a result when calling getFrameAtTime, this AV_FrameCapture can be used to extract a frame of video with accuracy.

https://stackoverflow.com/a/60633395/6676310

Upvotes: 0

wing zjq
wing zjq

Reputation: 81

retriever.getFrameAtTime(second* 1000*1000);

it need microsecond but not millisecond.

Upvotes: 1

user4286376
user4286376

Reputation: 40

ImageView imageView1=(ImageView)findViewById(R.id.imageView1);

Bitmap bm=ThumbnailUtils.createVideoThumbnail(Environment.getExternalStorageDirectory() + "/videocapture.3gp",Thumbnails.MICRO_KIND);

imageView1.setImageBitmap(bm);

Upvotes: -3

Cristi Maris
Cristi Maris

Reputation: 1341

Try to use without option ...

retriever.getFrameAtTime(time * 1000);

I had same issue and after I made this modification it worked perfect.

Upvotes: 2

Arif Nadeem
Arif Nadeem

Reputation: 8604

There is a bug in that function and it apparently won't work for small sized video's and is highly unreliable, I recently asked this question here on SO, see this post, but got no correct answers, so I did a lot of research and used FFMPEG instead, using FFMPEG I was able to extract Video Frames accurate to milliseconds, also note that the process of extracting frames on a mobile phone is slow and for a big video i.e. above 50Mb it often took me 2 mins to extract what I wanted.

Upvotes: 1

Related Questions