MATLAB Answers

how can i embedd an audio and deal with audio

2 ビュー (過去 30 日間)
ghadeer Alfaraidi
ghadeer Alfaraidi 2020 年 9 月 19 日
回答済み: Nitin Kapgate 2020 年 10 月 8 日
hello i wanted to ask how can i embedd and audio iside the video hoe can i deal with the audio?

  0 件のコメント

サインインしてコメントする。

回答 (1 件)

Nitin Kapgate
Nitin Kapgate 2020 年 10 月 8 日
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 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by