필터 지우기
필터 지우기

how can i embedd an audio and deal with audio

조회 수: 3 (최근 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?

답변 (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);

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by