如何在没有“NumberOfFrames”的情况下知道 MATLAB 中视频的帧数

How to know the number of frames of a video now in MATLAB without `NumberOfFrames`

MATLAB 似乎要删除一个 NumberOfFrames 选项。

我应该如何找出视频有多少帧?

示例:

Obj       = VideoReader( 'File.avi' );
numFrames = Obj.NumberOfFrames;

我尝试使用 FrameRate*Duration 来解决问题,但如果两者都不是整数,它有时无法正常工作。

更新:

我已经向 Mathworks 提交了请求,让我们等待他们的回复。

作为一种低效的解决方法,您可能需要使用 hasFrame() 方法来了解帧是否可供读取。在 while 循环中使用它,您可以遍历整个视频并收集最后一个计数器值作为帧数……这根本没有效率,但可以工作。

示例:

clc
clear

VideoObj = VideoReader('YourVideo.avi');

NumFrames = 0;
while hasFrame(VideoObj)

%// You can store the current frame into a mov structure. It completely defeats the efficiency since you can't pre-allocate and you are back to original problem though.

    CurrentFrame = readFrame(VideoObj)     
    NumFrames = NumFrames+1;
end

现在帧数存储在NumFrames

这个问题很有趣!

好的,我找到办法了

vid = VideoReader('video.avi');

numframes = int16(fix(vid.FrameRate*vid.Duration));