I need to do frame-by-frame analysis of videos. I can import the video files I need, but each file is too large to import at once. I can use the Import[fn, "Frames",{n}] command to import images one-by-one, but this takes a long time once n gets large. For example, the first frame it takes 0.14 sec, but the 200th frame takes 2.2 sec. Mathematica seems to be reading from the start of the file each time I do this. Obviously, this will not work.
Is there some way to speed this up. E.g. using streams? Or tricking Mathematica to use ImageCapture to get images from a video file instead of a webcam?
Thanks
|
|
||||
|
If you only want to read it linearly you can tell ffmpeg to dump the video to stdout and then read width*height*bytes-per-pixel bytes at a time to get the video frame-by-frame:
Here's an example:
For some reason Mathematica seems to read through the entire video when doing For a 720x404 h264 mp4 video on a modest laptop it takes 13s to skip 200 frames and 0.07s to read a frame. The skipping could possibly be sped up by starting a new ffmpeg process that begins at desired frame. I would compare speeds to |
||||
|
|



Import[movie, {"ImageList", Range[...]}]– cormullion Jan 24 at 7:56