在Matlab中跳帧和检索电影文件 [英] Skipping frames and retrieving movie file in Matlab

查看:34
本文介绍了在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?

错误信息:
    VideoReader"类型的输入参数的未定义函数step".

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.我发现 read 方法在我自己的应用程序中使用 1080p 60 fps MPEG-4 视频快十倍.随意修改代码以满足您的需求.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆