Genevieve
Genevieve

Reputation: 975

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.

Upvotes: 0

Views: 4018

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

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

Upvotes: 6

Related Questions