我想在Matlab中读取AVI文件。我根据这个链接尝试了它: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
我收到以下错误:
使用VideoReader / read时出错(第145行)请求的帧索引是 超出文件末尾。
test_video_read中的错误(第9行)I = read(movieObj,iFrame); %得到 一个RGB图像
(缩短)“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.任何人都可以帮忙,谢谢!
答案 0 :(得分:1)
我已经使用一些avi文件测试了你的Matlab代码,我对它们没有任何问题。所以,我认为这是导致错误的avi文件。
之前我遇到过类似的问题,我的(mp4)电影可以在任何媒体播放器中播放,但是matlab无法打开它们。在我的例子中,问题是mp4电影编译时的像素格式(通过ffmpeg)。默认情况下,我的电影是使用High 4:4:4 Predictive(yuv444p)格式编译的,但Matlab无法处理。当我切换到较旧的像素格式(yuv420p)时,我没有任何问题将电影加载到Matlab中。
您可以使用ffprobe检查这是否是问题,ffprobe是ffmpeg的一部分,您可以从https://www.ffmpeg.org下载它们。
否则,您是否尝试过未压缩的avi?
答案 1 :(得分:1)
使用ffmpeg编解码器构建VLC播放器。 VideoReader使用DirectShow和Media Foundation API,它们是Windows平台API,与ffmpeg不同。因此,如果使用VLC播放文件,则不保证VideoReader会打开它。你可以做的几件事:
希望这有帮助。
的Dinesh