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$

1 Answer 1

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
  • 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$ Commented Dec 24, 2015 at 9:01

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.