I have written the following code to extract all images from an uncompressed AVI movie and to save them as sequential PNGs.

outputPath = "F:\\images\\";

nImages = Length@Import["F:\\movie.avi", "Frames"];


  image = Import["F:\\movie.avi", {"Frames", i}];
  strCounter = ToString@PaddedForm[i, 4, NumberPadding -> {"0", ""}];
  Export[StringJoin[outputPath, "image_", strCounter, ".png"], image, "png"],

  {i, 1, nImages}

Can that be done faster?


1 Answer 1


You could speed things up by opening the file once for import since you are saving all of the frames.

 Function[{value, index},
  Export[StringJoin[outputPath, "image_", 
    PaddedForm[First@index, 4, NumberPadding -> {"0", ""}], ".png"], 
   value, "png"]],
 Import["F:\\movie.avi", "ImageList"]];

Hope this helps.

  • 1
    $\begingroup$ You forgot ToString@PaddedForm ... My AVI contains 10.6 GB (2726 PNGs), each PNG is 4MPixel. AbsoluteTiming gives for your code 1736.97 sec and for my code 589.802 sec. . (I have a 4 core i7.) So your code is 3 times slower. $\endgroup$
    – mrz
    Commented Dec 24, 2015 at 9:01

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.