classdef FFMPEGAudioCoderItem < CoderItem
    
    properties (Abstract)
        audiocodername;
        ext;
    end
    
    methods (Abstract)
        commandstring=getcommandstring(obj,inputfilename,outputfilename,inputparams);
    end
    
    methods
        function obj= FFMPEGAudioCoderItem(inputparams)
            obj=obj@CoderItem(inputparams);
        end
        
        
        function cicoll=procItem(obj,item)
            
            if not(exist('codedaudio','dir'))
                mkdir('codedaudio');
            end
            
            cicoll=CodedAudioItemCollection;
            
            if ~isfield(obj.params,'bitrate')
                
                    error('wrong parameters');

            end
            
            for currBitrate=obj.params.bitrate
                %A=imread(item.getfilename);
                [fpathstr,fname,fext] = fileparts(item.getfilename);
                infname=item.getfilename;
                % TODO check proper extension
                outfname=sprintf('codedaudio/%s_%s_%d.%s',...
                    fname,obj.audiocodername,round(currBitrate),obj.ext);
                
                params.bitrate=currBitrate;
                params.name=obj.audiocodername;
                commandstring=obj.getcommandstring(infname,outfname,params);
                if ~exist(outfname,'file')
                    dos(commandstring);
                end
                ci=CodedAudioItem(outfname,params,item);
                cicoll=cicoll+ci;
            end
        end
        
        
    end
    
    
end