title: ffmpeg - extract exact number of frames from video
body: <p>I want to create a maximum of 30 images from a video (and tile them for a sprite sheet).</p>
  
  <p>I've tried using the 'select' with 'mod' but if the total number of frames does not fit neatly into the desired number of images (30) then I sometimes end up with more images, sometimes less.</p>
  
  <p>For example if my video is 72 frames long, my 'mod' would be 72 / 30, which is 2.4.</p>
  
  <p>I'm running this from a python script so i'm doing something like the following for the filter:</p>
  
  <pre><code>select='not(mod(n\," + str(mod) + "))'
  </code></pre>
  
  <p>I think the mod has to be an integer (?) so I could either round down and use 2 which gives me 36 images or round up which gives me 24 images</p>
  
  <p>Whats the best way to get exactly 30? - obviously the interval wouldn't be identical but thats fine.</p>
  
  <p>Maybe I could use a for loop to generate a list of the frames closest to the desired interval and then pass that in as the select filter?</p>
  
  <p>e.g. to get the frames I would do something like this:</p>
  
  <pre><code>nframes = 72 # number of frames in video
  outImages = 30 # number of images I want
  mod = float(nframes) / outImages # 2.4
  
  frames = []
  
  idx = 1
  
  while i &lt; nframes:
      print str(idx) + ": " + str(math.floor(i+0.5)) 
      frames.append(int(math.floor(i+0.5)))
      idx += 1
      i += mod
  </code></pre>
  
  <p>Then am I able to pass that (the frames list) into the ffmpeg command? Or can I tell ffmpeg to do something similar?</p>