Matlab: Error using VideoFileReader/setup - matlab

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!

Related

Read DNG file in Matlab

I am trying to read dng files from iphoneX.
I read the link https://blogs.mathworks.com/steve/2011/03/08/tips-for-reading-a-camera-raw-file-into-matlab/
But the error message is 'Reference to non-existent field 'SubIFDs'.'
info=imfinfo(dng_file_path);
info.SubIFDs{1} %where the error pop up
tiffHandle=Tiff((dng_file_path),'r');
offsets=TiffHandle.getTag('SubIFD');
setSubDirectory(TiffHandle,offsets(1));
CFA=double(read(TiffHandle));
The DNG files from iphone seem to be compressed (lossless jpeg compression). Try running the file through DNG Converter with the preferences set to Uncompressed. Then try that in Matlab.

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: Writing avi file

I am having a problem when creating an avi file using Matlab. My aim is to use an edge filter on an entire video and save the file as an avi. The filter works fine, my problem is the writing of the avi file.
My code:
vidFile = VideoReader('video.avi');
edgeMov = avifile('edges','fps',30);
for i = 1:vidFile.numberofframes
frameI = read(vidFile,i);
frameIgray = rgb2gray(frameI);
edgeI = edge(frameIgray,'canny',0.6);
edgeIuint8 = im2uint8(edgeI);
edgeIuint8(:,:,2) = edgeIuint8(:,:,1);
edgeIuint8(:,:,3) = edgeIuint8(:,:,1);
edgeMov = addframe(edgeMov,edgeIuint8);
end
edgeMov = close(edgeMov)
When the loop finishes and the avifile is closed, I go to play the video and it says "Windows Media Player encountered a problem while playing this file". I've also tried, without success, Media Player Classic and VLC which lead me to believe that the problem must be the file itself. Using GSpot I checked the file and it said that the AVI header is corrupt.
Retrying the loop again returned exactly the same problem. What's confusing me is when I run the loop for a smaller number of frames, 30 for example, the video writes fine and I can watch it. The size of the video I am trying to convert is in excess of 1000 frames so I don't know if size is a problem?
Any help would be greatly appreciated, thank you.
I've used the following to create AVI
edgeMov = avifile('video.avi','compression','Indeo5','fps',15,'quality',95);
Give it a try.

Reading a movie file in 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)) ;