Read avi video - Matlab

…衆ロ難τιáo~ 提交于 2019-12-24 12:43:31

问题


I want to read an AVI File in Matlab. I tried it according to this 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

I get the following error:

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

(Shortened) Output from "get(movieObj)" is:

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

So it should be possible to read the first frame, as there are 310 available! I can play the AVI file in VLC-Player, so the codec should be already installed, right?

I'm using MATLAB R2013a, Windows 7. Can anyone please help, thank you!


回答1:


VLC player is built using the ffmpeg codecs. VideoReader uses DirectShow and Media Foundation API's that are Windows Platform API's and are different from ffmpeg. So, if a file plays using VLC, it is not guaranteed to be opened by VideoReader. Couple of things you can do:

  1. Can the file be viewed on Windows Media Player? If so, in most cases it should work with VideoReader. If not, then you do not have the suitable codecs. Try installing ffsdhow or K-lite codec pack.
  2. If file works on Windows Media Player but VideoReader does not support, it would indicate a bug. A workaround that has worked for me in the past is that I install codecs mentioned above and give it a try again.
  3. If (1) and (2) do not help, use software like handbrake or Mirro to transcode the file into MP4 which works win VideoReader.

Hope this helps.

Dinesh




回答2:


I have tested your Matlab code using some avi files and I have no problem with them. So, I think it is your avi file that is causing the error.

I have a similar problem before, where my (mp4) movies can be played in any media players but matlab cannot open them. In my case, the problem is the pixel format when the mp4 movies were compiled (by ffmpeg). By default, my movies were compiled with the High 4:4:4 Predictive (yuv444p) format but Matlab cannot handle this. When I switched to an older pixel format (yuv420p), I don't have any problem loading the movies into Matlab.

You can check if this is the problem using ffprobe, which is part of ffmpeg and you can download them from https://www.ffmpeg.org.

Otherwise, have you tried with an uncompressed avi?



来源:https://stackoverflow.com/questions/33063754/read-avi-video-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!