classdef FFMPEGVideoCoderItem < CoderItem
    
    properties (Abstract)
        videocodername;
    end
    
    methods (Abstract)
        commandstring=getcommandstring(obj,inputfilename,outputfilename,inputparams);
    end
    
    methods
        function obj= FFMPEGVideoCoderItem(inputparams)
            obj=obj@CoderItem(inputparams);
        end
        
        
        function cicoll=procItem(obj,item)
            
            if not(exist('codedvideos','dir'))
                mkdir('codedvideos');
            end
            
            cicoll=CodedVideoItemCollection;
            
            if ~isfield(obj.params,'bitrate')
                if isfield(obj.params,'compressionlevel')
                    obj.params.bitrate=obj.params.compressionlevel;
                else
                    error('wrong parameters');
                end
            end
            
            for currBitrate=obj.params.bitrate
                %A=imread(item.getfilename);
                [fpathstr,fname,fext] = fileparts(item.getfilename);
                infname=item.getfilename;
                outfname=sprintf('codedvideos/%s_%s_%d.mkv',...
                    fname,obj.videocodername,round(currBitrate));
                
                params.bitrate=currBitrate;
                params.name=obj.videocodername;
                commandstring=obj.getcommandstring(infname,outfname,params);
                if ~exist(outfname,'file')
                    dos(commandstring);
                end
                ci=CodedVideoItem(outfname,params,item);
                cicoll=cicoll+ci;
            end
        end
        
        
    end
    
    
end