Alex Rivera | Logout

Getting Frames From Videos Android

Asked 2012-04-11T08:13:40.390
12

I wanna get number of frames from video.. I m using following code:

package com.vidualtest;

import java.io.File;
import java.io.FileDescriptor;

import android.app.Activity;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ImageView;

public class VidualTestActivity extends Activity {
/** Called when the activity is first created. */
File file;
ImageView img;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


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

    File sdcard = Environment.getExternalStorageDirectory();
    file = new File(sdcard, "myvid.mp4");

    MediaMetadataRetriever retriever = new MediaMetadataRetriever();

    try {
        retriever.setDataSource(file.getAbsolutePath());

        img.setImageBitmap(retriever.getFrameAtTime(10000,MediaMetadataRetriever.OPTION_CLOSEST));


    } catch (IllegalArgumentException ex) {
        ex.printStackTrace();
    } catch (RuntimeException ex) {
        ex.printStackTrace();
    } finally {
        try {
            retriever.release();
        } catch (RuntimeException ex) {
        }
    }


}

}

here in getFrameAtTime() i m passing different static time like 10000,20000, etc. in milliseconds , but still i'm getting same frame from video within different time. My aim is to get different frames with different time interval.

Please get me your possible help.

Thanks

Edit
Report

1 Answer

0

I think getFrameAt() returns the frame thats closest to the time interval you specify. So specifying 1000 or 1500 as the time (in milliseconds) might return the same frame if the frame that's closest to both those time intervals is the same. To get the number of frames, you might want to get repetitive frames and then check whether they are distinct by just checking a few pixels. But you'll have to make sure that you don't miss any frames.

answered 2012-07-05T20:06:38.417

Your Answer