# Importing large number of frames form Video - improved method?

I am trying to work with large numbers of frames from a video (30000+). I see there are a number of answers out there, but I find none of them satisfying - see below for details.

I understand from painful experience that loading all frames from a video into memory via import is a bad idea. Instead I am trying to first export all individual frames of the video via an import/crop/export for-loop and will work on individual frames.

I find that import times of individual frames behave very different depending on what frames I want to import:

Table[{x, AbsoluteTiming[Import[vidName, {"Frames", x}]][[1]]}, {x, 1, 30000, 1000}]


I tried using the ffmpeg plugin as suggested here, but can not get it to run.

Likewise the pattern of how import times scale with number of simultaneously imported frames does take on an exponential shape rather than what Karolis observed:

LoadNFrames[n_] := (Import[vid, {"Frames", Range[1, 1 + n]}]; n);
times = Table[AbsoluteTiming[LoadNFrames[n]], {n, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 50,
75, 100, 150}}]


My question hence is: With importing behaving erratic like this, what is the single best way to extract images from videos to work on them? Do I really have to export frames in badges of 3 in a loop?

Thanks,

mondo

EDIT: ran my suggested single-frame import/crop/export loop and found some interesting pattern in the timing for each import:

Does this immediately make sense for anyone?

EDIT 2: I used the same method on another video. This time i get shuffled frame numbers - i.e., my exported frame number 5 fits after frame number 6, and before frame number 7 etc.

Any thoughts, anyone?

• Wouldn't it be better to do the video to frame image conversion with a free external software such as VirtualDub? – rhermans Aug 18 '15 at 11:35
• @rhermans Quite possible. Will look it up. Tested method as mentioned above overnight, see edit. – mondo Aug 19 '15 at 2:15
• Added another edit. Exported frames seem to jump in sequence... – mondo Aug 19 '15 at 13:14
• I think that this may be related to the compression algorithms that uses a sparse representation that depends on the data on previous frames. In order to extract 1 frame, you still need to read all the frames before. I bet an uncompressed video format would not have this behaviour. – rhermans Aug 19 '15 at 13:18
• Thanks for the thought @rhermans. Currently using .mov format - can you suggest a format in which this should not present a problem? Alternatively, should external software like VirtualDub (unfortunately not available for Mac, but I am sure there are alternatives) circumvent this problem? – mondo Aug 19 '15 at 13:28