FFmpegMediaMetadataRetriever icon indicating copy to clipboard operation
FFmpegMediaMetadataRetriever copied to clipboard

Extracting all frames

Open murod93 opened this issue 7 years ago • 2 comments

When I put less than 1 sec for extracting frames, it's returning the same. Below my code, `ArrayList<Bitmap> frameList;

    FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();

    try {
        mmr.setDataSource(absolutePath);
    }catch (Exception e) {
        System.out.println("Exception= "+e);
    }

    frameList = new ArrayList<Bitmap>();
    long duration = mmr.getMetadata().getLong("duration");
    double frameRate = mmr.getMetadata().getDouble("framerate");
    int numberOfFrame = (int) (duration/frameRate);

    for (int i = 0; i < numberOfFrame; i++)
    {
        Bitmap b = mmr.getFrameAtTime((long)frameRate*i, FFmpegMediaMetadataRetriever.OPTION_CLOSEST);
        frameList.add(b);
     }`

murod93 avatar Dec 13 '18 07:12 murod93

Hi, did you manage to solve this?

andreififiita avatar Apr 11 '19 13:04 andreififiita

In my case I wanted to calculate a videos timescale..


The problem is that FFmpegMediaMetadataRetriever doesn't return the exact/accurate frame rate. Instead of returning 23.976 it will return 23.98 for example.

It doesn't seem like much, but using your example:

long duration = mmr.getMetadata().getLong("duration");
double frameRate = mmr.getMetadata().getDouble("framerate");
int numberOfFrame = (int) (duration/frameRate);

The above numberOfFrame will be more than what there actually is, especially with videos with a longer duration. The longer the video duration the more inaccurate numberOfFrame will be.

So, that leaves us with 2 options,.

  • Since there is no API for Android to extract/read the exact frame rate, we will have to build a project like https://github.com/MediaArea/MediaInfoLib, that will cause our project to grow by 20 MB, plus the complications that comes with it.
  • OR, we can hope that @wseemann include this fix in the next build.

Perhaps there is a way to retrieve an accurate frame rate using FFmpegMediaMetadataRetriever, that is what my question is - > #204

HBiSoft avatar May 15 '19 04:05 HBiSoft