Search code examples
matlabaudiocompressionvideo-processing

Unable to create audio compressor filter


Function takes as input a string, the name of the video. It's read the video with the vision.VideoFileReader function and returns the same video, using thevision.VideoFileWriter function. Both the input video that the output videos have audio. Processing of a video about 6 MB, i have the output of a video more than 1 GB. The function has no errors, but i have to compress. Using the VideoCompressor, can compress the video up to 350 MB, i would use theAudioCompressor, but by obtaining an error. This is my code, the following is the error returned.

function [ nFrames ] = showMovie( video )
v = VideoReader(video);
videoFReader = vision.VideoFileReader(video);
videoFWriter = vision.VideoFileWriter('FrameRate',v.FrameRate,'AudioInputPort',1,'VideoCompressor', 'MJPEG Compressor','AudioCompressor','MJPEG Compressor');

[audio,fs] = audioread(video);
op=floor(fs/v.FrameRate);

nFrames = 0;

while ~isDone(videoFReader)
    nFrames=nFrames+1;
    frame=step(videoFReader);
    audios=audio( (nFrames-1)*op + 1 : nFrames*op , : );
    step(videoFWriter,frame,audios);
end

release(videoFReader);
release(videoFWriter);
end

I can't use the property AudioCompressor. I tried both the Compressor MJPEG and the DV Video Encoder value, but I get this error:

Error using VideoFileWriter / step
Unable to create audio compressor filter

Error in showMovie (line 15)

step (videoFWriter, frame, audios);

Solution

  • The only AudioCompressor compressor that works in my system is: 'None (uncompressed)'
    I tried it on 64 bit version of Matlab (R2014b).
    The reason for that is that my Windows system lacks x64 (64 bit) audio codec supported by Matlab.
    Note: 64 bit Matlab requires x64 codecs, and 32 bit Matlab requires x86 codecs.

    When I use videoWriter.AudioCompressor = ' % <tab> key as Suever mentioned,

    enter image description here

    When I tried the same code using 32 bit version of Matlab (R2013b), I got the following list:

    • AC-3 ACM Codec
    • AC-3 ACM Extensible
    • CCITT A-Law
    • CCITT U-Law
    • GSM 6.10
    • IMA ADPCM
    • Microsoft ADPCM
    • None (uncompressed)

    Note: The video codecs shown in 64 bit version, are not displayed in the 32 bit Matlab.
    I guess displaying video codecs in AudioCompressor is a Matlab bug.

    Just for the record, I tried the <tab> key before Suever posed his answer.
    I read about it in Matlab documentation: http://www.mathworks.com/help/vision/ref/vision.videofilewriter-class.html

    To launch the tab completion functionality, type the following up to the open quote.

    y.VideoCompressor='

    A list of compressors available on your system will appear after you press the Tab key

    The following code sample works in system:

    video = 'xylophone.mpg';
    
    v = VideoReader(video);
    videoFReader = vision.VideoFileReader(video);
    videoFWriter = vision.VideoFileWriter('FrameRate',v.FrameRate,'AudioInputPort',1,'VideoCompressor', 'MJPEG Compressor','AudioCompressor', 'None (uncompressed)');
    
    [audio,fs] = audioread(video);
    op=floor(fs/v.FrameRate);
    
    nFrames = 0;
    
    while ~isDone(videoFReader)
        nFrames=nFrames+1;
        frame=step(videoFReader);
        audios=audio( (nFrames-1)*op + 1 : min(nFrames*op, length(audio)) , : );
        
        %Handle last audio sample.
        if (length(audios) < op)
            audios = [audios; audios(1:op - length(audios), :)];
        end
        
        step(videoFWriter,frame,audios);
    end
    
    release(videoFReader);
    release(videoFWriter);
    

    I was searching the Web for free x64 audio codec that works with Matlab, but I couldn't find one.