在Matlab中跳过帧并检索电影文件 [英] Skipping frames and retrieving movie file in Matlab
问题描述
我正在尝试在Matlab中处理使用VideoReader
阅读的视频.我可以毫无问题地处理这些帧,但是我只想处理每五个帧.我尝试使用step函数,但不适用于我的videoreader对象.现在,我可以打电话给readFrame
五次,但这显然减慢了整个过程的速度(包括很多视频资料).如何使用Matlab有效地跳过五帧,处理五帧,再跳过五帧,...?
I am trying to process a video in Matlab that I read in using VideoReader
. I can process the the frames without a problem, but I only want to process every fifth frame. I tried using the step function but this doesn't work on my videoreader object. Right now I can call readFrame
five times, but this obviously slows down the whole process (its a lot of video material). How can I efficiently skip five frames, process five frame, skip another five, ... using Matlab?
错误消息:
未定义的函数"step",用于"VideoReader"类型的输入参数.
Error message:
Undefined function 'step' for input arguments of type 'VideoReader'.
但是,在step
上调用help
函数可以得到以下示例:
However, calling the help
function on step
gets me this example:
WORKED=step(VR,DELTA)
Moves the frame counter by DELTA frames for video VR. This is a
generalization of NEXT. Returns 0 on an unsuccessful step. Note that
not all plugins support stepping, especially with negative numbers. In
the following example, both IM1 and IM2 should be the same for most
plugins.
vr = videoReader(...myurl...);
if (~next(vr)), error('couldn''t read first frame'); end
im1 = getframe(vr);
if (~step(vr,-1)), error('could not step back to frame 0'); end
im2 = getframe(vr);
if (any(im1 ~= im2)),
error('first frame and frame 0 are not the same');
end
vr = close(vr);
FNUM should be an integer.
After the videoReader constructor is called, NEXT, SEEK, or step should
be called at least once before GETFRAME is called.
在这里,step
显然是在VideoReader
对象上调用的,不是吗?帮助将不胜感激.
Here, step
is clearly called on a VideoReader
object, is it not? Help would be greatly appreciated.
推荐答案
我也遇到了这个问题.在不使用不推荐使用的代码的情况下,要做的唯一方法是调用每个输出帧readFrame
五次.这是缓慢且非常低效的.但是,如果您使用不推荐使用的 read
方法(以及(假设您的视频是文件而不是视频流),则也可以指定帧号.我不知道为什么MathWorks在这方面倒退.我建议您提出服务请求进行询问并说出原因功能对您很重要.
I've had this issue too. Without using deprecated code, the only way to do what you are trying is to call readFrame
five times for every output frame. This is slow and very inefficient. However, if you use the deprecated read
method (and assuming your video is a file rather than a stream), you can specify a frame number as well. I don't know why The MathWorks have gone backwards on this. I suggest that you file a service request to ask about it and say why this functionality is important to you.
同时,您可以试用我的 frame2jpg
函数从视频文件中提取特定的帧.它尝试使用不建议使用的read
方法,如果失败,则退回到readFrame
.我发现在我自己的应用程序中使用1080p 60 fps MPEG-4视频时,read
方法的速度要快十倍.随时修改代码以适合您的需求.
In the meantime, you can try out my frame2jpg
function that extracts particular frames from a video file. It tries to use the deprecated read
method and falls back to readFrame
if that fails. I've found the read
method to be ten times faster in my own application with 1080p 60 fps MPEG-4 video. Feel free to modify the code to suit your your needs.
这篇关于在Matlab中跳过帧并检索电影文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!