wseemann / FFmpegMediaMetadataRetriever

FFmpegMediaMetadataRetriever provides a unified interface for retrieving frame and meta data from an input media file.
1.72k stars 387 forks source link

Frames missing from extraction. #241

Open namhkoh opened 3 years ago

namhkoh commented 3 years ago

I am currently developing a feature where a system can extract frames from a video every second. For the most part, I am able to extract the frames every second but notice that it always stops before the last frame of the video. For instance, if the video is 10 seconds long, it seems to extract up to 9 seconds.

Here is the method:

`private void extractImageFrame(String absPath) throws IOException {

    FFmpegMediaMetadataRetriever med = new FFmpegMediaMetadataRetriever();
    med.setDataSource(absPath);
    String time = med.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);
    int videoDuration = Integer.parseInt(time);
    Log.e("video duration", String.valueOf(videoDuration));

    for (int i = 1000000; i < videoDuration * 1000; i += 1000000) {
        Bitmap bmp = med.getFrameAtTime(i, FFmpegMediaMetadataRetriever.OPTION_NEXT_SYNC);
        Log.d("Frame extracted at ", String.valueOf(i));
        saveBit(bmp);
    }

}`

Is this normal?

Thank you.