Extracting audio from video files - matlab

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

Related

Ros publisher not working with V-Rep after saving

I've started using V-Rep to simulate some robots (Pioneers and quadrotors, initially), but I've been having problems when I try to connect it with ROS. I tried to replicate the example from RosTopicPublisherAndSubscriber.ttt and it only works the first time, after I close it and load it again, it doesn't work anymore, my code is practically identical to the example, except that I use getPose and it's a Pioneer (the one that comes with V-Rep), here's my code:
if (simGetScriptExecutionCount()==0) then
-- Check if the required plugin is there (libv_repExtRos.so or libv_repExtRos.dylib):
local moduleName=0
local moduleVersion=0
local index=0
local pluginNotFound=true
while moduleName do
moduleName,moduleVersion=simGetModuleName(index)
if (moduleName=='Ros') then
pluginNotFound=false
end
index=index+1
end
if (pluginNotFound) then
simDisplayDialog('Error','ROS plugin was not found.&&nSimulation will not run properly',sim_dlgstyle_ok,false,nil,{0.8,0,0,0,0,0},{0.5,0,0,1,1,1})
else
-- Retrive the handle of the vision sensor we wish to stream:
lHandle=simGetObjectHandle('Pioneer_p3dx')
-- Now enable topic publishing and streaming of the vision sensor's data:
topicName=simExtROS_enablePublisher('p3dx',1,simros_strmcmd_get_object_pose,lHandle,0,'')
if (topicName == nil) then
simDisplayDialog('Error','Nil',sim_dlgstyle_ok,false,nil,{0.8,0,0,0,0,0},{0.5,0,0,1,1,1})
else
simDisplayDialog('Error','Not Nil',sim_dlgstyle_ok,false,nil,{0.8,0,0,0,0,0},{0.5,0,0,1,1,1})
end
-- Retrive the handle of the passive vision sensor. We will use the passive vision sensor
end
end
Any idea is welcome! Thanks in advance!
PS: Also, if anyone with 1500 reputation points could create the v-rep tag, that would be great!
Ok, the people at V-REP helped me solve it. So basically I should used the argument as -1 instead of 0.
So basically, a should have done this
topicName=simExtROS_enablePublisher('p3dx',1,simros_strmcmd_get_object_pose,lHandle,-1,'')
instead of
topicName=simExtROS_enablePublisher('p3dx',1,simros_strmcmd_get_object_pose,lHandle,0,'')

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.

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)) ;