Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Extract frame from video in Android

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 5.95k
    Comment on it

    There are many cases where one need to extract frames from video irrespective of its length. With the given function one can retrieve the desired number of frames per second.

        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) )
            }
    

 2 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: