-
How to take frame from video
almost 9 years ago
-
almost 9 years ago
Below is the code
ArrayList<Bitmap> frameList; String absolutePath; /* MediaMetadataRetriever class is used to retrieve meta data from methods. */ MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { //path of the video of which you want frames retriever.setDataSource(absolutePath); }catch (Exception e) { System.out.println("Exception= "+e); } // created an arraylist of bitmap that will store your frames frameList = new ArrayList<Bitmap>(); String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); int duration_millisec = Integer.parseInt(duration); //duration in millisec int duration_second = duration_millisec / 1000; //millisec to sec. int frames_per_second = 2; //no. of frames want to retrieve per second numeroFrameCaptured = frames_per_second * duration_second; for (int i = 0; i < numeroFrameCaptured; i++) { //setting time position at which you want to retrieve frames frames.add(retriever.getFrameAtTime(5000*i) ) }
Hope, It will help you. :)
-
1 Answer(s)