I am reading large AVI files and want to know the number of stored frames.
To do that in Mathematica 11.3 I use the following:
Needs["MediaTools`"];
numberImages = MediaTools`Private`$MFReadVideoFrameCount["movie.avi"];
This second line takes too much time (e.g. 205 sec for finding out that an AVI movie contains 4325 frames).
I am working with thousands of such and longer AVI files, and if I always have to wait for some minutes to find the total frame number it would sum up for thousand files to 3000 min = 50 hours!!! (In reality more.)
I there a possibility to read the value from the header?
For example VirtualDub (free Software for Windows) reads the information in a fraction of a second and the value is exact, not estimated! I tested this for hundreds of AVI files. My AVI files are experimental movie files where the correct number is written into the header.
Addendum
After the comments of Buddha_the_Scientist and C. M. I would like to provide some additional information:
Here is an example avi movie (named "20181203_01_movie.avi", only 1 MB in size): https://drive.google.com/open?id=1Wmp0YGZtKTYxBd2nGzgyglJKrNb_Uk0_
First step:
Needs["MediaTools`"];
numberImages = MediaTools
Private
$MFReadVideoFrameCount[ "20181203_01_movie.avi"] // AbsoluteTiming{4.16492, 350}
Second step with restarted kernel:
numberImages = Import["20181203_01_movie.avi", "FrameCount"] // AbsoluteTiming
{3.96804, 350}
So for this very small avi file it takes about 4 sec to read the total number of images (350).
Now lets take exiftool: I downloaded the Windows Version from here: https://www.sno.phy.queensu.ca/~phil/exiftool/
On Windows command shell cmd:
"exiftool(-k).exe" lower_center.avi
That gives instantaneously the total frame count of 350 and many other data from the header:
Question to the Mathematica experts:
How can I read the meta information WITH Mathematica? I cannot believe that I have to use an external program to do that.
Import["movie.avi", "FrameCount"]
but I assume it is equally slow. $\endgroup$ffprobe
, a companion tool toffmpeg
, to get the frame count of a 1330 frames long video, and that took 18 seconds. I usedexiftool
to look at what metadata the file held, and the frame count is not supplied as metadata. So maybe it actually has to go through all the frames, and that may be what's taking time. In that case, there may not be a very fast solution for an exact frame count, although frame rate and duration could be used to estimate. $\endgroup$exiftool
orffprobe
and see if they find this. If you useffprobe
the command is this:ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 movie.avi
It is easy to callffprobe
from Mathematica. See this and this. This is along the lines of Buddha_the_Scientist's suggestion of using VirtudalDub via the command line. $\endgroup$