retriever.getFrameAtTime always return the same frame

26 Views Asked by At

This code saves frames every 0.25s into a jpeg file. But it gives me almost always the same frame.

FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever();
retriever.setDataSource(url, new HashMap<String, String>());
String durationStr = retriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);
long duration = Long.parseLong(durationStr);


long time = 0;
// Process each frame
Log.d("Video Service" , "Duration of the video : " + duration / 1000.0);
while(time < duration) {
    // Get the frame at the specified time
    Bitmap frameBitmap = retriever.getFrameAtTime(time * 1000, FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC); // get frame at one second
    Log.d("Video Service", "Current duration : " + String.valueOf((double) time/1000.0));
    ImageService.saveBitmapAsJPEG(context, frameBitmap, String.valueOf(time));
    time+= 250;
}

// Release the MediaMetadataRetriever
retriever.release();

I know there are multiple posts having the same issue but they don't solve my problems.

This one says it is microsecond. I do use microsecond in my code so this is not the problem.

This one says it's better to use FFmpeg instead of native android API, but i use FFmpeg and it still does the same.

I have tried many things and still I get the save frame saved again and again.

Any idea?

0

There are 0 best solutions below