VideoReader on .asf video file NumFrames Property is empty

4 次查看(过去 30 天)
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

采纳的回答

Aashita Dutta
Aashita Dutta 2023-1-9
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
Please refer to the documentation for imagesc , drawnow and readFrame for further information.
Hope that helps!

更多回答(1 个)

Walter Roberson
Walter Roberson 2023-1-9
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.

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by