function [varargout] = read_ith_GOP_keyframe(GOP,gopsz,width,height,filename)



fid = fopen(filename) ;



for frames = 1 : (GOP)*gopsz

    frame_data = fread(fid,width*height*1.5,'uint8') ;

end

imgY = zeros(height,width) ;

imgU = zeros(height/2,width/2) ;

imgV = zeros(height/2,width/2) ;

num_key_within_GOP = 1 ;

    for frames = 1 : num_key_within_GOP

        %%%%%%%%%% Y data %%%%%%%%%%%%%%%%%

        frame_data = fread(fid,width*height*1.0,'uint8') ;

        for i = 1 : height

            for j = 1 : width

                imgY(i,j) = frame_data((i-1)*width+j) ;

            end

        end

        imgY = double(imgY) ;

        varargout(1) = {imgY} ;

        

        %%%%%%%%%% U data %%%%%%%%%%%%%%%%%

        frame_data = fread(fid,width*height*0.25,'uint8') ;

        for i = 1 : height/2

            for j = 1 : width/2

                imgU(i,j) = frame_data((i-1)*width/2+j) ;

            end

        end

        imgU = double(imgU) ;

        varargout(2) = {imgU} ;

        

        %%%%%%%%%% V data %%%%%%%%%%%%%%%%%

        frame_data = fread(fid,width*height*0.25,'uint8') ;

        for i = 1 : height/2

            for j = 1 : width/2

                imgV(i,j) = frame_data((i-1)*width/2+j) ;

            end

        end

        imgV = double(imgV) ;

        varargout(3) = {imgV} ;

    end



fclose(fid) ;

