Internal: How can I read video file frames into IDL?
Help Article Update 2
Anonym
IDL has built-in capability to write and read frames to and from animated GIF files and Motion JPEG2000 files. However, as of IDL 8.1, IDL can write MP4 and AVI video files, using the IDLffVideoWrite object, but cannot read frames from these file formats.
To read MP4 or AVI video frames into IDL, you would need to use to extract frames from the target video file to save as individual image files, which could then be read into IDL.
This Help Article discusses the use of the "ffmpeg" command line utility to extract frames from and AVI or MP4 video file, saving the frames to JPEG image files, which can be read by IDL.
IDL can read in animated GIF files and Motion JPEG2000 files. Otherwise, to read the frames from videos created with IDLffVideoWrite (mp4 and avi files) into IDL, one would have to use an external library or utility to read frames from a video file. For example, the www.FFmpeg.org web site provides a package that includes an ffmpeg program that can do this:
http://www.ffmpeg.org/download.html
From the section 6.3 of the documentation for "FFmpeg" (http://www.ffmpeg.org/ffmpeg.html) you'll see the following:
"You can extract images from a video, or create a video from many images: For extracting images from a video:
ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
This will extract one video frame per second from the video and will output them in files named `foo-001.jpeg', `foo-002.jpeg', etc. Images will be rescaled to fit the new WxH values. If you want to extract just a limited number of frames, you can use the above command in combination with the -vframes or -t option, or in combination with -ss to start extracting from a certain point in time."
For example, to extract 400x400 pixel frames/1 per second to JPEG files from an MP4 video file:
ffmpeg -i mytest.mp4 -r 1 -s 400x400 -f image2 foo-%03d.jpeg
To automate frame extraction and reading of frames into IDL, perhaps a "ffmpeg.exe" call like above can be spawned from IDL in order to extract video frames, and subsequently have an IDL program read the resulting image files.