1
$\begingroup$

What's the most straightforward way to "Import" the data of an AVI video? For instance, if I record a 30 frame per second video, then after 10 seconds I would have 300 frames. How can I import the data of all frames at once (without running of the memory)?

$\endgroup$
  • 1
    $\begingroup$ @MarcoB Thanks, already tried. But is there anyway to directly extract the data? or at list instead of Import, Export the image list? $\endgroup$ – faf May 26 '16 at 19:17
  • 3
    $\begingroup$ I recommend using FFmpeg to convert video to images (example here), then use Mathematica to import images. Mathematica seems slow to me to work on video directly. $\endgroup$ – xslittlegrass May 26 '16 at 20:22
  • 2
    $\begingroup$ faf, ImageData can be applied to each image / frame to obtain an array containing the pixel values. However, I would concur with @xslittlegrass that Mathematica can be very slow when working with videos. What do you need to do with the data after you import it? Perhaps there's another, more efficient way. $\endgroup$ – MarcoB May 26 '16 at 20:37
  • 1
    $\begingroup$ @faf I understand that, which is why I mentioned two things in my previous comment that will help us help you. If you don't have memory enough on your computer to hold all frames in memory at once, then you can't import all frames at once. It's an impossible question. $\endgroup$ – C. E. May 27 '16 at 12:54
  • 1
    $\begingroup$ @faf Look in the documentation for "AVI", under "Elements". $\endgroup$ – C. E. May 30 '16 at 10:04
3
$\begingroup$

Here is an example of using FFmpeg to convert a video to images and import them into Mathematica. I'm using the jfkrice.avi video as an example.

This will convert the video to a list of images

ffmpeg -i jfkrice.avi -r 10 -f image2 jfkrice/%05d.png

the number 10 means 10 images per second.

Then we can use Mathematica to import them

imgls = Import /@ FileNames["jfkrice/*.png"];

Now you can manipulate the images, for example, make an edge detected image3D object:

Image3D[EdgeDetect /@ imgls]

enter image description here

$\endgroup$
  • $\begingroup$ From the image in the answer I did expect a video about something like an internal-combustion engine but found a video with Bill Klinton. :( $\endgroup$ – Alexey Popkov May 27 '16 at 14:51
  • $\begingroup$ Actually, it is John F Kennedy :) $\endgroup$ – xslittlegrass May 27 '16 at 15:28

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.