6
$\begingroup$

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"];

ParallelTable[

  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?

$\endgroup$
6
$\begingroup$

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

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

Hope this helps.

$\endgroup$
  • 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 Dec 24 '15 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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