how can i embedd an audio and deal with audio

3 visualizaciones (últimos 30 días)
ghadeer Alfaraidi
ghadeer Alfaraidi el 19 de Sept. de 2020
Respondida: Nitin Kapgate el 8 de Oct. de 2020
hello i wanted to ask how can i embedd and audio iside the video hoe can i deal with the audio?

Respuestas (1)

Nitin Kapgate
Nitin Kapgate el 8 de Oct. de 2020
You can use the following code snippet to embed the audio in a video file:
% Assuming your input file is named as "inputVideo.avi", read the video file
v = VideoReader('inputVideo.avi');
% Create a video file writer object.
% "AudioInputPort" property controls whether the object writes audio samples to the video file.
% Set this value to true to write audio data.
% To write audio and video to a file, you must use the .avi format.
videoWriterObj = vision.VideoFileWriter('OutputVideo.avi','AudioInputPort',true);
% total number of frames in input video
nFrames = v.NumFrames;
% assign FrameRate of input video to output video
videoWriterObj.FrameRate = v.FrameRate;
% Read the input audio file, assuming your input audio file is named as "inputAudio.wav"
[y,Fs] = audioread('inputAudio.wav');
% length of the audio samples to be put per frame
samplesPerFrame = round(size(y,1)/nFrames);
for k = Fs : nFrames
% Read one video frame at a time
Frame = readFrame(v);
% add the audio samples to the variable in the step function
step(videoWriterObj,Frame,y(samplesPerFrame*(k-1)+1:samplesPerFrame*k,:)); % Assuming two channel stereo audio
end
% release the video reader object
release(v);
% release the video file writer object
release(videoWriterObj);

Community Treasure Hunt

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

Start Hunting!

Translated by