hi i hve to add audio file to video file ...but im getting error plz help me..
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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
Walter Roberson
on 10 Oct 2016
Edited: Walter Roberson
on 10 Oct 2016
Your call to vision.videoFileWriter needs to add 'AudioInputPort', true
9 Comments
Gohan
on 10 Oct 2016
Edited: Walter Roberson
on 11 Oct 2016
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??
Walter Roberson
on 10 Oct 2016
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....
Walter Roberson
on 11 Oct 2016
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)
Gohan
on 12 Oct 2016
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);
Walter Roberson
on 12 Oct 2016
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
Gohan
on 12 Oct 2016
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
Gohan
on 12 Oct 2016
Thanku so much sir I'm getting output ....
More Answers (0)
Categories
Find more on Signal Processing Toolbox in Help Center and File Exchange
Products
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)