阅读 avi 视频 - Matlab

Read avi video - Matlab

我想在 Matlab 中读取 AVI 文件。我按照这个试了一下 link: http://inside.mines.edu/~whoff/courses/EENG512/lectures/other/Matlab_movies.pdf :

clear all
close all
movieObj = VideoReader('ap001_BL0_SP2_cam03_compressed.avi'); % open file
get(movieObj) % display all information about movie
nFrames = movieObj.NumberOfFrames; %shows 310 in my case
for iFrame=1:2:nFrames
    I = read(movieObj,iFrame); % get one RGB image
    imshow(I,[]); % Display image
end

我收到以下错误:

Error using VideoReader/read (line 145) The frame index requested is beyond the end of the file.

Error in test_video_read (line 9) I = read(movieObj,iFrame); % get one RGB image

(缩短)"get(movieObj)" 的输出是:

General Settings: 
   Duration = 10.3333
   Name = ap001_BL0_SP2_cam03_compressed.avi
   Type = VideoReader

Video Settings:
   BitsPerPixel = 24
   FrameRate = 30
   Height = 1280
   NumberOfFrames = 310
   VideoFormat = RGB24
   Width = 960

所以应该可以读到第一帧,因为有310个可用! 我可以在VLC-Player中播放AVI文件,所以编解码器应该已经安装了吧?

我正在使用MATLAB R2013a,Windows 7. 谁能帮忙,谢谢!

我已经使用一些 avi 文件测试了您的 Matlab 代码,我没有遇到任何问题。所以,我认为是您的 avi 文件导致了错误。

我之前也遇到过类似的问题,我的(mp4)电影可以在任何媒体播放器中播放,但matlab无法打开它们。就我而言,问题是编译 mp4 电影时的像素格式(由 ffmpeg)。默认情况下,我的电影是使用 High 4:4:4 Predictive (yuv444p) 格式编译的,但 Matlab 无法处理。当我切换到较旧的像素格式 (yuv420p) 时,将电影加载到 Matlab 中没有任何问题。

您可以使用 ffprobe 检查这是否是问题所在,ffprobe 是 ffmpeg 的一部分,您可以从 https://www.ffmpeg.org 下载它们。

否则,您是否尝试过使用未压缩的 avi?

VLC 播放器是使用 ffmpeg 编解码器构建的。 VideoReader 使用 DirectShow 和 Media Foundation API,它们是 Windows 平台 API,并且与 ffmpeg 不同。因此,如果文件使用 VLC 播放,则不能保证 VideoReader 可以打开它。您可以做几件事:

  1. 可以在 Windows 媒体播放器上查看文件吗?如果是这样,在大多数情况下它应该可以与 VideoReader 一起使用。如果没有,那么您没有合适的编解码器。尝试安装 ffsdhow 或 K-lite 编解码器包。
  2. 如果文件在 Windows Media Player 上运行但 VideoReader 不支持,则表示存在错误。过去对我有用的解决方法是我安装上面提到的编解码器并重试。
  3. 如果 (1) 和 (2) 没有帮助,请使用 handbrake 或 Mirro 等软件将文件转码为 MP4,这样可以在 VideoReader 中使用。

希望对您有所帮助。

迪内什