No BSD License  

Highlights from
Scalable MPEG compression based on DCT coefficients

Scalable MPEG compression based on DCT coefficients

by

 

15 Nov 2006 (Updated )

This application makes 2 layers base Layer and enhancement layer from quantized coefficients

main(fileName, quantizationTable,outputfilename,estAlgo)
function main(fileName, quantizationTable,outputfilename,estAlgo)

if nargin ~= 4
  disp('You must provide a filenames for avifile and quantization table as the input.');
  disp('Usage: main(fileName,quantizationTable,outputfilename,motionEstimation Algorithm)');
  disp('1 for Adaptive Rood Pattern Search method');
  disp('2 for Diamond Search method');
  disp('3 for Exhaustive search method');
  disp('4 for Three Step Search method');
  return;
  elseif ~isa(fileName,'char') || ~isa(quantizationTable,'char') || ~isa(outputfilename,'char')
  disp('File names are not a valid');
  return;
elseif (estAlgo > 5) | (estAlgo < 1)
  disp('Not a valid number');
  return;
end

tic
 GOPindex=0;

try
    aviobj = avifile(outputfilename,'fps',25,'COMPRESSION','None');
catch ME
    disp(ME.message);
    return;
end


motionVect=zeros(2,256);

try
    fid=fopen(quantizationTable,'r');
    array=fscanf(fid,'%e',[8,inf]);
catch ME
    disp(ME.message);
    return;
end






flag=2;
XX=[];
BB=[];
dim=128;
mbSize = 16;
p = 7;

global I1d P4d P7d I10d B2d B3d B5d B6d B8d B9d

imagedata = fileName;
try
    framedata=aviread(imagedata,1);
catch ME
    disp(ME.message);
    return;
end

I1=frame2im(framedata);

I1=imresize(I1,[dim dim]);
%I1=rgb2gray(I1);

I1=double(I1);
JQ=forwardDCT(I1,array);
bufferI1 = inverseDCT(JQ,array);
[X,B]= makeLayers(JQ);
XX(1)=length(X);
BB(1)=length(B);


%%calling decoder
identifier=1;
decoder(X,B,motionVect,identifier,flag);

for i=1:10:321
    if i~=1
        j=i-round(i/10);
        [B2,B3,P4,B5,B6,P7,B8,B9,I10]=GOP(imagedata,j,dim);
    elseif i==1
        j=i;
        [B2,B3,P4,B5,B6,P7,B8,B9,I10]=GOP(imagedata,j,dim);
    end
        %processing on P4 frame
        [bufferP4,streamP4,motionVect]=compensatedFrame(P4,bufferI1,mbSize,p,array,estAlgo); 
        [X,B]= makeLayers(streamP4);
        XX(4)=length(X);
        BB(4)=length(B);

        
        %calling decoder
        identifier=4;
        decoder(X,B,motionVect,identifier,flag);



% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
        
        %for B2    
        [B2t ,motionVect, flag] = bFrameProc(B2,bufferI1,bufferP4,1.4*array,mbSize,p);
        [X,B]= makeLayers(B2t);
        XX(2)=length(X);
        BB(2)=length(B);

        
        %calling decoder
        identifier=2;
        decoder(X,B,motionVect,identifier,flag);
        
        %for B3    
        [B3t ,motionVect ,flag] = bFrameProc(B3,bufferI1,bufferP4,1.4*array,mbSize,p);
        [X,B]= makeLayers(B3t);
        XX(3)=length(X);
        BB(3)=length(B);

        
        %calling decoder
        identifier=3;
        decoder(X,B,motionVect,identifier,flag);
 
        %predicting p7 from p4
        [bufferP7,streamP7,motionVect]=compensatedFrame(P7,bufferP4,mbSize,p,array,estAlgo);
        [X,B]= makeLayers(streamP7);
        XX(7)=length(X);
        BB(7)=length(B);

        
        %calling decoder
        identifier=7;
        decoder(X,B,motionVect,identifier,flag);
%          
        %for B5    
        [B5t motionVect flag] = bFrameProc(B5,bufferP4,bufferP7,1.4*array,mbSize,p);
        [X,B]= makeLayers(B5t);
        XX(5)=length(X);
        BB(5)=length(B);

        
        %calling decoder
        identifier=5;
        decoder(X,B,motionVect,identifier,flag);
   
        %for B6    
        [B6t motionVect flag] = bFrameProc(B6,bufferP4,bufferP7,1.4*array,mbSize,p);
        [X,B]= makeLayers(B6t);
        XX(6)=length(X);
        BB(6)=length(B);

        
        %calling decoder
        identifier=6;
        decoder(X,B,motionVect,identifier,flag);
 
        %processing on I10 frame
        streamI10=forwardDCT(I10,array);
        bufferI10 = inverseDCT(streamI10,array);
        [X,B]= makeLayers(streamI10);
        XX(10)=length(X);
        BB(10)=length(B);

        
        %%calling decoder
        identifier=10;
        decoder(X,B,motionVect,identifier,flag);
%         
        %for B8    
        [B8t motionVect flag] = bFrameProc(B8,bufferP7,bufferI10,1.4*array,mbSize,p);
        [X,B]= makeLayers(B8t);
        XX(8)=length(X);
        BB(8)=length(B);

        
        %calling decoder
        identifier=8;
        decoder(X,B,motionVect,identifier,flag);

        %for B9    
        [B9t motionVect flag] = bFrameProc(B9,bufferP7,bufferI10,1.4*array,mbSize,p);
        [X,B]= makeLayers(B9t);
        XX(9)=length(X);
        BB(9)=length(B);

        
        %calling decoder
        identifier=9;
        decoder(X,B,motionVect,identifier,flag);
    
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                if i==1

                aviobj = addframe(aviobj,im2frame(uint8(I1d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B2d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B3d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(P4d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B5d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B6d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(P7d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B8d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B9d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(I10d),gray(256))); 
            else
                aviobj = addframe(aviobj,im2frame(uint8(B2d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B3d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(P4d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B5d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B6d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(P7d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B8d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B9d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(I10d),gray(256))); 

            end
            GOPindex=GOPindex+1;
    if i==1
        for ii=1:10

            compressionratioWOE(GOPindex,ii)=(XX(ii)+BB(ii))/(dim*dim*8);
        end
    else 
        for ii=2:10

            compressionratioWOE(GOPindex,ii-1)=(XX(ii)+BB(ii))/(dim*dim*8);
        end
    end

            I1=I10;
            bufferI1=bufferI10;
            I1d=I10d;

end
toc

aviobj = close(aviobj);

Contact us