how can i embedd an audio and deal with audio
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hello i wanted to ask how can i embedd and audio iside the video hoe can i deal with the audio?
0 commentaires
Réponses (1)
Nitin Kapgate
le 8 Oct 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);
0 commentaires
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!