I'm looking to import 100 image frames from an mp4 video file at roughly evenly spaced intervals. As $ImportFormats shows, Mathematica can handle

  • Movie files: .avi, .mov, .qt, .flv
  • Multiframe images: .swf, .tiff, .gif

If I convert the video it to a supported type, what would the syntax be to achieve this import, I don't want to import all the frames and then take a few!


1 Answer 1


You can use Import directly as follows:

Import["MVI_9855-183.mp4", {"AVI", "ImageList", Range[1, 110, 20]}]

This will import one frame every 20, between the first and 100th, and return them as a list of pictures.

Mathematica graphics

As you can see above, at least in the case of the mp4 files I have at hand I was able to "convince" Mathematica to import them directly by specifying the AVI format for the file. I am no expert in video file format, however, so I can't claim that I understand why that worked, or whether it will work for you as well.

If you are on Windows, you may also be interested in Simon Woods's MathMF package that carried out video input output functions using Windows Media Foundation. See it described in his answer to this question: Importing videos in Mathematica

  • $\begingroup$ Weird! Nice trick though, do you know how to get the total frame count? $\endgroup$
    – M.R.
    Commented Jul 6, 2015 at 0:04
  • $\begingroup$ Oh it's just "FrameCount" $\endgroup$
    – M.R.
    Commented Jul 6, 2015 at 0:14
  • $\begingroup$ And the "AVI" is not necessary. $\endgroup$
    – M.R.
    Commented Jul 6, 2015 at 0:14
  • $\begingroup$ @M.R. so it works without the "AVI" on your side even if the file extension is not *.avi? That's interesting: if I try to feed an *.mp4 file directly to Import it fails, saying "Cannot import data as ImageList". $\endgroup$
    – MarcoB
    Commented Jul 6, 2015 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.