【问题标题】:How to read a particular video frame by its frame index in Matlab?如何通过 Matlab 中的帧索引读取特定视频帧?
【发布时间】:2019-04-10 07:13:27
【问题描述】:

我正在研究一种算法,该算法通过其索引获取单个视频帧,对其进行处理并获取新索引的下一个视频帧。

我正在使用 Matlab VideoReader 函数读取视频文件。为了读取下一帧,它提供了 readFrame 函数。

readFrame 函数可以获取帧的时间并在那时读取该特定帧。如何使用它来读取给定索引处的特定帧?

我在 Linux 中使用 Matlab 2016b。我有 mmread 函数,它采用视频文件名和帧索引来读取帧。但是这个文件依赖于Windows 64位编译的Matlab函数文件,所以我不能用。

这是我的使用方法:

for i = startIdx:endIdx
    frame = mmread(filename, i);
    ...
    processing the frame
    ...
end

这是我从 Windows 中获得的 mmread 函数的 link。

【问题讨论】:

  • 请添加您现有的代码,以便我们查看。

标签: matlab


【解决方案1】:

您可以使用read 函数。但是文档表明不建议这样做(我不知道为什么)。

v = VideoReader(filename);

for i = startIdx:endIdx
    frame = read(v,i);
    ...
    processing the frame
    ...
end

【讨论】:

    【解决方案2】:

    补充@ga97dil 的答案。正如他所说,Matlab 建议不要使用read 函数,而是建议使用VideoReader.readFrame 函数来读取帧。

    由于此函数不将帧索引作为参数,而是将读取帧的特定时间作为参数,我想如果我可以将特定帧索引转换为视频中的时间会怎样。谷歌搜索了一下,我发现this 线程作为解决方案。

    这是我定义新 mmread.m 函数的方式

    function [ frame ] = mmread_1(filename, frameIdx)
        v = VideoReader(filename);  % read the video file
        v.CurrentTime = (frameIdx - 1) / v.FrameRate;  % calculate the time for the given frame index
        frame = readFrame(v);  % read the frame
    end
    

    由于 Matlab 建议不要使用 read 功能(可能会在以后的版本中删除),由于可移植性,我不想使用它。

    【讨论】:

      猜你喜欢
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      • 2014-08-24
      相关资源
      最近更新 更多