title: Retrieving frames per second - Android / MediaMetadataRetriever
body: <p>I'm looking to retrieve 10 frames per sec on a 5 second video using the MediaMetadataRetriever and store them into an Arraylist. I'm not interested in using ffmpeg. </p>
  
  <p>Currently my application is creating 50 still images - 10 identical frames AT every second interval instead of 10 different frames PER second. </p>
  
  <pre><code>public class FrameCollector {
  
  MediaMetadataRetriever mmr;
  
  double fps;
  double duration;
  long counter = 0;
  long incrementer;
  
  public FrameCollector(String path, Context context) 
  {
      try
      {
      mmr = new MediaMetadataRetriever();
      mmr.setDataSource(path);
  
      SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
      String fpsString = pref.getString("prefFPS", "10");
      fps = Double.parseDouble(fpsString);
      incrementer = (long) (1000000 / fps);
  
      String stringDuration = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
      duration = Double.parseDouble(stringDuration) * 1000;
      }
      catch(Exception ex)
      {
          ex.printStackTrace();
      }
  }
  
  public ArrayList&lt;Bitmap&gt; getBitmaps() 
  {
      try 
      {
          ArrayList&lt;Bitmap&gt; bitFrames = new ArrayList&lt;Bitmap&gt;();
  
          Bitmap b = mmr.getFrameAtTime(counter);
  
          while (counter &lt; duration &amp;&amp; b != null) 
          {
              bitFrames.add(b);
              counter += incrementer;
              b = mmr.getFrameAtTime(counter);
          }
          return bitFrames;   
      }
      catch (Exception ex) 
      {
          ex.printStackTrace();
          return null;
      }
    }
  }
  </code></pre>