MATLAB: Use of vision.VideoFileWriter and vision.VideoFileReader

1.2k views Asked by At

I'm trying to convert a .avi file with audio to a .mp4 file. I wrote this script 'avi2mp4.m' using the Computer Vision System Toolbox v7.2 with the MATLAB R2016b.

vfr = vision.VideoFileReader('Cris Drift vs Patrick.avi', 'AudioOutputPort',true);
vfw = vision.VideoFileWriter('Cris Drift vs Patrick.mp4', 'FileFormat','MPEG4', 'AudioInputPort',true, ...
                           'FrameRate',vfr.info.VideoFrameRate, 'Quality',90);
while ~isDone(vfr)
    [frame, audio] = vfr();      % [frame, audio] = step(vfr);
    vfw(frame, audio);           % step(vfw, frame, audio);
end
release(vfr);
release(vfw);

but i get this error:

Error using vision.VideoFileWriter/parenReference Too many input arguments; expected 1 (in addition to the object handle), got 2.

Error in avi2mp4 (line 16) vfw(frame, audio);

I don't know why? I have to pass the audio data as an argument to write it with the video data. It's the same syntax as described in the MATLAB Documentation

1

There are 1 answers

5
Navan On

With vision.VideoFileWriter you can write both audio and video only when the format is AVI or WMV. If you received a warning about AudioInputPort property not relevant when you set that property that means audio is not supported in that configuration.