Reading a movie file in Matlab - matlab

I am trying to read a movie in avi format. But it's giving me the following error:
xyloObj = mmreader('1.avi',[1 5]);
??? Initialization failed. (No combination of intermediate filters could be found to make the connection.)
Error in ==>
mmreader.mmreader>mmreader.init at 423
obj.MMReaderImpl = audiovideo.mmreader(fullName);
Error in ==>
mmreader.mmreader>mmreader.mmreader at 133
obj.init(fileName);
Kindly help me

The likely source of the error is that you are missing the proper codec required to read the given AVI file. Apparently, this can often happen when using 64-bit versions of MATLAB on 64-bit Windows platforms. There are a number of solutions you can try given in this technical support documentation from the MathWorks.

First, can you play it with another application (such as VLC player, Windows Media Player, QuickTime, etc.) on your computer?
If yes, go to gnovice's link.
If no, go get the GSpot codec information tool which is very useful for determining which codec you need. Download the codec and make it work with a video player, then Matlab.

This pdf explains how to solve your problem. Or just use:
vid = aviread('Vid261.avi');
vi = frame2im(vid(1)) ;

Related

Extracting audio from video files

I just received a 30 day trial of the Computer Vision System Toolbox, and I just tested it out. I found this code online that separates video from audio:
file='movie.AVI';
file1='targetfile.wav';
hmfr= video.MultimediaFileReader(file,'AudioOutputPort',true,'VideoOutputPort',false);
hmfw = video.MultimediaFileWriter(file1,'AudioInputPort',true,'FileFormat','WAV');
while ~isDone(hmfr)
audioFrame = step(hmfr);
step(hmfw,audioFrame);
end
close(hmfw);
close(hmfr);
but I can't run it, I only get the error:
Undefined variable "video" or class "video.MultimediaFileReader".
I'm not quite sure what this means, does it refer to my code or the computer vision system toolbox? I checked, I have all the requirements and the add-on manager says it's properly installed, so I'm not quite sure why I get this error.
I think your task is quite easier than you think it is. It can be done without any reliance on toolboxes.
That's how:-
1. Read your video file and get its sample rate using audioread.
2. Then use audiowrite to write it as an audio file.
[input_file, Fs] = audioread('movie.AVI');
audiowrite('target_file.WAV', input_file, Fs);
%If your path is set to default then MATLAB may give you 'Permission Denied' Error.
%Change the path or give different full path like: 'D:\target_file.WAV' while audiowriting

Issues with Movie2Avi

I'm trying to make a movie in the following way:
x=linspaces(1,10,100);
For i=1:100
plot(x,sin(x))
M(i)=getframe;
end
movie2avi(M,'MOVIE01');
I get a response:
Warning: Cannot locate Indeo5 compressor, using 'None' as the compression type.
it makes the movie but I cannot open it ( gives an error)
I'm using windows 7 64 bit operation system and matlab 2012b
I've tryed the compression types in the documentation but recieved an error for all of them
From the docs:
On some Windows systems, including all 64-bit systems, the default Indeo® 5 codec is not available. MATLAB issues a warning, and creates an uncompressed file.
It would be better to use VideoWriter, which I believe you should have in 2012b.

Matlab: Error using VideoFileReader/setup

I'm using this code:
h = vision.VideoFileReader('num2.avi')
h =
System: vision.VideoFileReader
Properties:
Filename: '/Users/LoFe/Documents/BME/Work/Work/Work/num2.avi'
PlayCount: Inf
ImageColorSpace: 'RGB'
VideoOutputDataType: 'single'
It is working well, but when I want to call step on it, i get this:
while ~isDone(h)
hFrame = step(h);
end
Error using VideoFileReader/setup
Could not open the specified file.
Error in
/Applications/MATLAB_R2013a.app/toolbox/matlab/system/+matlab/+system/+mixin
/FiniteSource.p>FiniteSource.isDone
(line 39)
I'm using MATLAB 2013a, on OS X (Mavericks), what should I do? It is working fine on Windows 7.
As we discussed in the comments, the codec that was used to encode the video is may not supported on your Mac. For MATLAB, the supported codecs that the CVST video reader can read in are different between Mac and Windows.
As such, try re-encoding your video into a format that is native to the Mac, like a QuickTime movie file, or an MP4 file. HandBrake is a perfect tool to do this for you.
Also, perhaps try using MATLAB's native VideoReader class to see if you can read the file and extract video frames. Take a look at its documentation for more details: http://mathworks.com/help/matlab/ref/videoreader-class.html.
However, it looks like you have resolved the error, as converting it to a QuickTime movie file worked.
Glad I could help!

RTSP Source Filter with GDCL MP4 Muxer incompatibility

I'm trying to use GDCL MP4 Muxer with my RTSP Source Filter. They work fine together except after stopping the graph, muxer doesn't finilize the file and write the reqiured tables to the end of file via file writer (some parts are written starting from moov but not the time table values). When I try another RTSP source filter (which I don't have its source codes), table values are created with GDCL MP4 Muxer.
But when I try Elecard's MP4 Muxer, it works fine with my RTSP Source Filter. So, there is an incompatibility. I examined GDCL's source codes but couldn't find what it was expecting from me. I already calculate and set timestamp values to samples using SetTime method. But GDCL still doesn't finilaze file. Is it caused by missing information or missing signal when graph stops? What can be the problem, any ideas?
One thing you should be aware of regarding Geraint's MP4 Mux is that it is checking incoming media samples to have both start and stop time. You might be having only .tStart/AM_SAMPLE_TIMEVALID which still makes sense for video, but this would be a problem.
So the samples have to have stop time, or you need to fix this in multiplexer code.
A typical symptom for the problem is that generated files are empty or of zero duration.

x264 IDR access unit with a SPS and a PPS

I am trying to encode video in h.264 that when split with Apples HTTP Live Streaming tools media file segmenter will pass the media file validator I am getting two errors on the split MPEG-TS file
WARNING: Media segment contains a video track but does not contain any IDR access unit with a SPS and a PPS.
WARNING: 7 samples (17.073 %) do not have timestamps in track 257 (avc1).
After hours of research I think the "IDR" warning relates to not having keyframes in the right place on the segmented MPEG-TS file so in my ffmpeg command I set -keyint_min 1 to ensure keyframes where at every frame, but this didn't work.
Although it would be great to get an answer, if anyone can shed any light on what a "IDR access unit with a SPS and a PPS" is or what the timestamps warning means I would be very grateful, thanks.
Fix can be found on this thread https://devforums.apple.com/thread/45830?tstart=15