Search code examples
matlabcomputer-visionvideo-processingmatlab-cvst

video read in matlab -audio output port is not relavant


If i execute this statement or the similar videoFileWriter or even multimediafilereader in matlab 2012b

videoFileReadera = vision.VideoFileReader(filename,'AudioOutputPort',true);

i am getting warning as

Warning: The AudioOutputPort property is not relevant in this configuration of the System object.

or with AudioInputPort...

i know its just a warning but the object fails to read or write the audio file??

please tell me how to read a video and audio combined file and to write it back as a single video and audio combined file.


Solution

  • clear all;
    close all;
    clc;
    VidObj=VideoReader('E:\workspace\mat2012b\video compression\original.mp4');
    n=VidObj.NumberOfFrames;
    videoFReader = vision.VideoFileReader('original.mp4');
    videoFWriter = vision.VideoFileWriter('vid_new_compressed_ffd5.avi',...
       'AudioInputPort',1,'AudioDataType','int16','VideoCompressor','ffdshow video encoder','FileFormat','avi',...
       'FrameRate',videoFReader.info.VideoFrameRate);
    [audio,fs]=audioread('original.mp4');
    op=floor(fs/videoFReader.info.VideoFrameRate);
    
    for i=1:n
        videoFrame= step(videoFReader);
        audios=audio( (i-1)*op + 1 : i*op , : );
        step(videoFWriter, videoFrame,audios);
    end
    
    release(videoFReader);
    release(videoFWriter);
    

    This above code reads an audio and video and writes back to audio and video. I tried to get .mp4 as output it didnt work. This code can give .avi and .wmv as output.