2

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

glennsl
  • 28,186
  • 12
  • 57
  • 75

1 Answers1

0

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.

Navan
  • 4,407
  • 1
  • 24
  • 26
  • I customized the code for the VideoFileWriter object `vfw = vision.VideoFileWriter('Chris_Drift_vs_Patrick.avi', 'FileFormat','AVI', 'AudioInputPort',true, 'FrameRate',vfr.info.VideoFrameRate);`. Now this error is displayed "Error using VideoFileWriter/parenReference Could not create the ASF Writer profile." Same with AVI format –  Dec 22 '16 at 17:33
  • Can you report what is the size of the video and audio, adn the frame rate? – Navan Dec 22 '16 at 17:43
  • The AVI file includes the audio data. Information about the AVI file: size = 200 Mbyte, video bit rate = 81819 kbits/s, audio bit rate = 512 kbit/s, frame rate = 60 –  Dec 23 '16 at 00:45
  • This video has a duration of 25 s: file size = 247 Mbyte, video size = 200 Mbyte, audio size = 12.5 Mbyte –  Dec 23 '16 at 00:49
  • Hi @B0bbyR4y I was looking for the size in terms of dimensions of the video (rows x cols) and number of samples in audio data in one call to the video file writer method. Some times video codecs might not support odd frame sizes. – Navan Dec 23 '16 at 13:41