Currently saving video to avi file. Can I add audio to the file?

4 views (last 30 days)
I currently am successfully recording video to an avi file. I would like to record audio and add it to the same file. Is this possible?
%Create a video input object for the logitech webcam
vid = videoinput('winvideo',1 );
%Create an audio input object for the computer's microphone
audio = audiorecorder(sps,16,1,4);
%audio
record(audio);
% Grab every frame
set(vid,'FrameGrabInterval',1);
% Specify a trigger to fire (specifically, fire a trigger after 100 frames)
set(vid, 'FramesPerTrigger', 100);
% Get a file name
Today = datestr(now, 'dd-mm-yyyy');
data_file = strcat(dataFolder, Today, '.avi');
% Create an AVI file object to hold the frames
avi = avifile(data_file,'fps',15, 'compression', 'none');
% Log the images
set(vid,'LoggingMode','disk'); % Log to disk
set(vid,'DiskLogger',avi); % Log the disk to the AVI file object
% Start the video input object
start(vid);
% Wait (i.e., block) for the given amount of time or until a trigger is
% fired (whichever comes first). In this case, the trigger
% will be fired after 100 frames.
%
% Note that other MATLAB code can be executing since the
% Image Acquisition Toolbox runs in another thread of execution
wait(vid,20); % Could use Inf
% After the trigger is fired...
% Get the AVI object
avi = get(vid,'DiskLogger');
% Close the AVI file
avi = close(avi);
% Free the hardware resources associated with the video input
delete(vid);
stop(audio);
% Remove the video object from the workspace
clear vid;

Accepted Answer

Walter Roberson
Walter Roberson on 15 Apr 2014
Only the Computer Vision Toolbox has the capability of working with combined audio and video.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!