hi i hve to add audio file to video file ...but im getting error plz help me..

my code is
videoFReader = vision.VideoFileReader('audio.avi');
[AUDIO,Fs] = wavread('audio.wav');
videoFWriter = vision.VideoFileWriter('myfile.avi');
videoFrame = step(videoFReader);
step(videoFWriter,videoFrame,AUDIO);
release(videoFReader);
release(videoFWriter);
both are different files im getting error as
Error using vision.VideoFileWriter/step
Too many input arguments; expected 1 (in addition to the object handle), got 2.
Error in ex (line 5)
step(videoFWriter,videoFrame,AUDIO);

 Accepted Answer

Your call to vision.videoFileWriter needs to add 'AudioInputPort', true

9 Comments

videoFReader = vision.VideoFileReader('viptraffic.avi');
[AUDIO,Fs] = wavread('handel.wav');
videoFWriter = vision.VideoFileWriter('myfilee1e2.avi','AudioInputPort',true);
for i=1:100
videoFrame = step(videoFReader);
step(videoFWriter,videoFrame,AUDIO);
end
release(videoFReader);
release(videoFWriter)
sir I made changes but im getting video file with noisy sound ...no music file ...where I made mistake sir??
You should be passing in only one frame of audio samples each time. If your frame rate is 30 frames per second you should pass in 1/30th of a second of audio data.
Sir can u plz give me an example or any code version to understand it....
videoFReader = vision.VideoFileReader('viptraffic.avi');
[AUDIO,Fs] = wavread('handel.wav');
framerate = 30;
framebounds = [floor(1 : Fs/framerate : size(AUDIO,1)), size(AUDIO,1)+1];
videoFWriter = vision.VideoFileWriter('myfilee1e2.avi', 'FrameRate', framerate, 'AudioInputPort',true);
for i = 1:100
videoFrame = step(videoFReader);
if i >= length(framebounds)
this_audio_frame = []; %no audio left to put into movie
else
this_audio_frame = AUDIO(framebounds(i) : framebounds(i+1)-1, :);
end
step(videoFWriter, videoFrame, this_audio_frame);
end
release(videoFReader);
release(videoFWriter)
sir thank you so much but im getting one error sir Error using vision.VideoFileWriter/step Changing the size on input 2 is not allowed without first calling the release() method.
Error in Untitled2 (line 17) step(videoFWriter, videoFrame, this_audio_frame);
framebounds = 1 : floor(Fs/framerate) : size(AUDIO,1);
Another way to proceed would be to split your audio into one variable (or cell member) per channel, and then use the buffer() function with size floor(Fs/framerate) per frame. Use i pull the appropriate column out.
You will have a problem with accumulation of round-off error on the number of samples. For example if you had 1000 samples per second and a frame rate of 30, then that would round down to 33 audio samples per frame. Put 30 of those frames together and you would have only reached 990 samples instead of 1000. The code I posted before was intended to partition up the samples unequally if need be in order to avoid that kind of accumulated error; unfortunately it appears that the file writer does not approve.
To get around this issue you might want to consider using a resample routine so that each frame gets the same number of samples.
Watch out as well for the end of audio in the middle of a frame.
Sir I tried it but it is giving only a fraction of second video with audio ...sir ful video not saving ...with the change of frame bounds syntax
Sir I'm getting video and audio only a fraction of second sir ... Only to a single frame the audio samples are added ...resultant video has only a fraction of second video with audio
Thanku so much sir I'm getting output ....

Sign in to comment.

More Answers (0)

Categories

Find more on Signal Processing Toolbox in Help Center and File Exchange

Products

Asked:

on 10 Oct 2016

Commented:

on 12 Oct 2016

Community Treasure Hunt

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

Start Hunting!