VideoReader on .asf video file NumFrames Property is empty
3 views (last 30 days)
Show older comments
Hi, I have tried to read the .asf video file using VideoReader and all properties work fine (the video duration is 253.8140 and has a frame rate of 30 etc.) except for the NumFrames property, which empty. Can anyone please help me to solve this issue?
videoIn = VideoReader("carvideo.asf");
numFrames = videoIn.NumFrames;
![NumFrames property is empty](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1254697/NumFrames%20property%20is%20empty.jpeg)
0 Comments
Accepted Answer
Aashita Dutta
on 9 Jan 2023
Hello Ching,
I understand that you are getting empty NumFrames property while trying to read ASF file using ‘VideoReader’ function.
Please find the script below that can help resolve the issue of empty NumFrames:
vidObj = VideoReader('carvideo.asf');
numFrames = 0;
while hasFrame(vidObj)
F = readFrame(vidObj);
numFrames = numFrames + 1;
imagesc(F)
drawnow
end
NumFrames
Hope that helps!
More Answers (1)
Walter Roberson
on 9 Jan 2023
Historically, VideoReader had only one property for asking about the number of frames. The original property operated by reading every frame of the video and counting them, and that was automatically done when VideoReader was invoked. But that was slow and often not necessary.
Mathworks then added a second frame count property that is initialized to an estimate of the number of frames, based on the time recorded and the nominal number of frames per second in the header. If some operation is done that reads through all of the frames then the property is updated to the actual number.
The estimated number of frames is not accurate for variable frame-rate videos. But it can also be off for NTSC frame rates because software is often sloppy about writing in 30 frames per second in the header, or at best recording 29.98 frames per second in the header, which is closer but still not exact.
Against all of this, it turns out that Microsoft's asf video format does not have the needed header information to estimate the frame count, so the frame count ends up being reported as 0... at least until some operation reads all of the frames sequentially.
Aashita showed how to read all of the frames and count them. Another way that in theory should work is to use readFrame to read all of the frames and throw away the results, after which the property should be correct. If reading all of the frames could overfill memory then you could loop readFrame a group of frames at the time, which should be more efficient than reading them one by one.
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!