使用音频在Matlab R2015b中编写视频时出错

时间:2016-02-23 15:23:46

标签: matlab audio video

我正在编写一个函数,用于在视频中输入mp​​3中的某些声音,如果我尝试保存mp4文件,则会出错。如果是avi文件,则可以。问题是avi会大得多。错误是:

  

使用vision.VideoFileWriter / step时出错输入参数太多;   预期1(除了对象句柄),得到2.错误   p10_see_only_positive                   step(videoFWriter,im,au);

这是我的代码:

function p10_see_only_positive(str)
% function to put audio and video together

video_str = sprintf('./videos/%s.mp4', str);

% found out how many frames does the video have
vid = VideoReader(strcat('./videos/', str, '.mp4'));

% check input
if exist(video_str,'file') == 2
    cap = cv.VideoCapture(video_str);
    [y, fs] = audioread(sprintf('./videos/%s.mp3', str));

    val = fs/vid.FrameRate;
else
    error('Input file not exist');
end

% prepare video
videoFWriter = vision.VideoFileWriter(sprintf('./videos/final_%s.mp4', str), ...
    'FrameRate', vid.FrameRate, 'FileFormat', 'MPEG4', ...
    'AudioInputPort', true);

for ii = 1:10000
    im = cap.read;
    au = y(val*(ii - 1) + 1: val*ii, :);

    if isempty(im)
        warning('End of file');
        break;
    else
        step(videoFWriter, im, au);
    end
end

fprintf('Video: %d\n', nvid);

release(videoFWriter);
end

这是mp4中的VideoFileWriter:

val = 

  Properties:
          Filename: './videos/final_jornal_all_1.mp4'
        FileFormat: 'MPEG4'                          
         FrameRate: 25                               
    FileColorSpace: 'RGB'                            
           Quality: 75  

现在是avi一个:

val = 

  Properties:
           Filename: './videos/final_jornal_all_1.mp4'
         FileFormat: 'AVI'                            
     AudioInputPort: true                             
          FrameRate: 25                               
    AudioCompressor: 'None (uncompressed)'            
    VideoCompressor: 'None (uncompressed)'            
     FileColorSpace: 'RGB' 

我猜mp4格式无法识别音频输入。

有任何变通方法吗?

0 个答案:

没有答案