I'm trying to get all frames (one by one) from a video, right now I'm using this :
int framesCount = videoInformation.getFramesCount();
for (int i = 0; i < framesCount; i++) {
Bitmap currentFrame = mediaMetadataRetriever.getFrameAtIndex(i);
For 5 sec video, it's take 13 seconds to extract all frames (159 frames).
Since getFrameAtIndex(i) requires API 28, I tried to use getFrameAtTime()
long timeS = videoInformation.getDuration() / videoInformation.getFps();
int framesCount = videoInformation.getFramesCount();
for (int i = 0; i < framesCount; i++) {
Bitmap currentFrame = (mediaMetadataRetriever.getFrameAtTime(i*timeS*1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC));
For the same 5 sec video, it's take almost 48sec to get all frames.
I cant speak for the native implementations for both, as both of these functions call their respective native functions, however, if you look at the
getFrameAtIndex, you can see that it:Has access to the total
framecountby reading themetadata, and retrieves a frame using anindex, similar toArrays.getFrameAtIndex()callsgetFramesAtIndexInternal()while
getFrameAtTimeis not really index based, but rather seeks/searches until it matches a Frame timestamp with the required time you passed, or the closest one:https://github.com/aosp-mirror/platform_frameworks_base/blob/master/media/java/android/media/MediaMetadataRetriever.java