How can get frames in Android? [closed]

asked 2014-05-21 02:21:46 -0600

vinoth gravatar image

Actually i need to get all the frames from videos but I use to get first frame repeatedly then specific time frames while using Mediametadatareteriver,thumbnail,timestamp to get frames.

I'd tried a lot for fixing by changing all GetFrameAtTime(options) but remains the same.

my Duration of video is 127040(2:07sec) here i Splited as 32 frames and save frames in SDCard can view all 32 but repeatedly same frames for all 32 frames.

I should get these without the help of FFMPEG and xuggler.

Is there any alternatives methods or any other Library files for using in Android if there please help me Friends.

Here is my full code

import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Random;

import android.graphics.Bitmap; import android.media.MediaMetadataRetriever; import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.view.Menu; import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    File videoFile=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Movies/MEMO.mp4";

    Uri videoFileUri=Uri.parse(videoFile.toString());

    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(videoFile.getAbsolutePath());
    ArrayList<Bitmap> rev=new ArrayList<Bitmap>();


    //Create a new Media Player
    MediaPlayer mp = MediaPlayer.create(getBaseContext(), videoFileUri);
    int millis = mp.getDuration();
    for(int i=0;i<millis;i+=100){
       Bitmap bitmap=retriever.getFrameAtTime(i,MediaMetadataRetriever.OPTION_CLOSEST);
       rev.add(bitmap);

      try {
          saveFrames(rev);
    } catch (IOException e) {

        e.printStackTrace();
    }
    }
}



public void saveFrames(ArrayList<Bitmap> saveBitmapList) throws IOException{

    String folder = Environment.getExternalStorageDirectory().toString();
    File saveFolder = new File(folder + "/Movies/new /";
    if(!saveFolder.exists()){
       saveFolder.mkdirs();
    }


    int i=1;
    for (Bitmap b : saveBitmapList){
       ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        b.compress(Bitmap.CompressFormat.JPEG, 40, bytes);

        File f = new File(saveFolder,("frame"+i+".jpg");

        f.createNewFile();

        FileOutputStream fo = new FileOutputStream;
        fo.write(bytes.toByteArray());

           fo.flush();
           fo.close();

        i++;
    }

}
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2014-05-21 02:33:37.929059

Comments

sorry dear, but this is entirely unrelated to opencv.

well, opencv can't help you here, it neither can read or write video files on android, due to missing backend.

berak gravatar imageberak ( 2014-05-21 02:28:21 -0600 )edit