Use of vision.VideoFileWriter and vision.VideoFileReader

10 Ansichten (letzte 30 Tage)
Bruno Kempf
Bruno Kempf am 22 Dez. 2016
Kommentiert: Saffana Siddiqua am 28 Jan. 2020
Hi,
I'm trying to convert a .avi file with audio to a .mp4 file. I wrote this code using the Computer Vision System Toolbox 7.2 (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
Thanking you in anticipation! Kind regards Bruno
  2 Kommentare
Walter Roberson
Walter Roberson am 22 Dez. 2016
It appears to me that it might be a bug, and that step(vfw, frame, audio) would probably work. But could you confirm that you are using R2016b or newer? The syntax you used is new in R2016b.
Bruno Kempf
Bruno Kempf am 22 Dez. 2016
Hi Walter, yes I'm using R2016b (Computer Vision Toolbox 7.2). I will add that information in my question. Thanks

Melden Sie sich an, um zu kommentieren.

Antworten (2)

vinoth kumar
vinoth kumar am 9 Apr. 2018
Bearbeitet: Walter Roberson am 23 Dez. 2019
vfw = vision.VideoFileWriter('Cris Drift vs Patrick.mp4', 'FileFormat','MPEG4', 'AudioInputPort',true, ...
'FrameRate',vfr.info.VideoFrameRate, 'Quality',90);
if you want to add audio to your video means you should choose .avi FileFormat and try
  4 Kommentare
Emilien GACOGNE
Emilien GACOGNE am 22 Dez. 2019
Hello Vinod, or anyone else who could help me,
I am facing the same error...
Why is writing in a MPEG4 file does not work with audio whereas it works when writing in an AVI file...
For both I am using the instruction:
step(videoFWriter, videoFrame,audios)
How then can I just cut an MP4 video into a smaller part of this video (still in MP4) without any quality loss ?
Thanks in advance for your reply ;)
Emilien
Saffana Siddiqua
Saffana Siddiqua am 28 Jan. 2020
hi vinoth, i used the object but it showing error

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 23 Dez. 2019
You need to set AudioInputPort to true for the writer, not the reader. From the help:
"Write audio data, specified as false or true. Use this property to control 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 ."
So it appears you can only add audio for an .avi format, not an .mp4 format video.

Community Treasure Hunt

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

Start Hunting!

Translated by