Use of vision.VideoFileWriter and vision.VideoFileReader
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2016 年 12 月 22 日
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.
回答 (2 件)
vinoth kumar
2018 年 4 月 9 日
編集済み: Walter Roberson
2019 年 12 月 23 日
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 件のコメント
Emilien GACOGNE
2019 年 12 月 22 日
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
Image Analyst
2019 年 12 月 23 日
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!