Video and audio acquisition

4 views (last 30 days)
BHASKAR
BHASKAR on 11 Jun 2021
Answered: Rahul on 22 Nov 2024 at 7:51
Hello all, Could you please tell me how can I record audio and video simultaneously??
I found vision tool box supports separate acquisition of audio and video and then writing to a single file. But I want to acquire audio and video from same device. No need to write to a single file.
Thank you.

Answers (1)

Rahul
Rahul on 22 Nov 2024 at 7:51
In order to achieve the desired result of recording audio and video simultanteously, consider using 'videoinput' and 'audiorecorder' functions. The 'start', 'stop' functions for the 'videoinput' object and 'record', 'stop' functions for the 'audiorecorder' object can be used simultaneously.
If the video is to be recorded using webcam of a Windows device, the 'Image Acquisition Toolbox Support Package for OS Generic Video Interface' will need to be installed. Here is an example of how to set up the 'videoinput' and 'audiorecorder':
vid = videoinput('winvideo', 1);
vid.FramesPerTrigger = Inf;
vid.LoggingMode = 'memory'
Fs = 44100;
nBits = 16;
nChannels = 1;
% These values can be adjusted
recObj = audiorecorder(Fs, nBits, nChannels);
The 'getdata' and 'getaudiodata' functions can be used to obtain the data from the 'videoinput' and 'audiorecorder' functions respectively.
In order to play the audio and video, you can use the 'sound' and 'implay' functions respectively. Here is an example:
videoFrames = getdata(vid);
audioData = getaudiodata(recObj);
sound(audioData, Fs); % Play audio using 'sound' function
implay(videoFrames); % Play video using 'implay' function
Refer to the following MathWorks documentations to know more:
Thanks.

Community Treasure Hunt

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

Start Hunting!