Please help my Matlab code work
-
Hi everyone I've got this project on MATLAB where i'm trying to read in a YUV file. Below are the m files within my work directory <pre lang="matlab">function [width,height,fps,startpos,NumberFrames]=readheader(fid) %******************************************************** % This function will read the header of a bath yuv file % % This file is used by readyseq and should not be used on its own. % % N.Young % 5 June 2001 %******************************************************** FileFormat = []; %The first line will contain one of the following %1. YUV 4:2:0 %2. RVS RAW YUV 4:2:0 %read the format descriptor for i=1:17 FileFormat = [FileFormat fscanf(fid,'%c',1)]; %Check to see if it is yuv 420 (i.e. number 1 above) if i==9 if FileFormat == 'YUV 4:2:0' disp('File format is : YUV 4:2:0'); FileFormat=0; break; end end %Check to see if it is rvs raw yuv 420 (i.e. number 2 above) if i==17 if FileFormat == 'RVS RAW YUV 4:2:0' disp('File format is : RVS RAW YUV 4:2:0'); FileFormat=1; break; end end %if we get here and i is 17, we have an unsupported FileFormat if i==17 disp('Unknown file format') FileFormat = 2; end end if FileFormat==0 [width,height,fps,startpos,NumberFrames] = readyuvheader(fid); end</pre> <pre lang="matlab">function [width,height,y]=readyseq(filename,start,stop) %******************************************************** % Function to load a bath yuv file % % Syntax : [width,height,ysequence] = readyseq(filename,start frame,end frame) % % NOTE: the frames are numbered from 0. % % A.N.Evans & N.Young % 5 June 2001 %******************************************************** %Note that I have to use some C functions here. I know some people dont like %mixing matlab with c, I'm affraid its un avoidable. %First we need to open the file [fid,msg] = fopen(filename,'r'); %if msg is longer than 0, i.e. it has something in it, we have an error if length(msg) > 0 disp('Error opening the file.'); else %read the header info [width,height,fps,startpos,NumberFrames] = readheader(fid); if start < NumberFrames & stop < NumberFrames %Now we can read the given frames. i=1; for frame = start:stop %now read the required frame y(i,:,:)=readyframe(fid,width,height,startpos,frame); i=i+1; end end end fclose(fid);</pre
-
Hi everyone I've got this project on MATLAB where i'm trying to read in a YUV file. Below are the m files within my work directory <pre lang="matlab">function [width,height,fps,startpos,NumberFrames]=readheader(fid) %******************************************************** % This function will read the header of a bath yuv file % % This file is used by readyseq and should not be used on its own. % % N.Young % 5 June 2001 %******************************************************** FileFormat = []; %The first line will contain one of the following %1. YUV 4:2:0 %2. RVS RAW YUV 4:2:0 %read the format descriptor for i=1:17 FileFormat = [FileFormat fscanf(fid,'%c',1)]; %Check to see if it is yuv 420 (i.e. number 1 above) if i==9 if FileFormat == 'YUV 4:2:0' disp('File format is : YUV 4:2:0'); FileFormat=0; break; end end %Check to see if it is rvs raw yuv 420 (i.e. number 2 above) if i==17 if FileFormat == 'RVS RAW YUV 4:2:0' disp('File format is : RVS RAW YUV 4:2:0'); FileFormat=1; break; end end %if we get here and i is 17, we have an unsupported FileFormat if i==17 disp('Unknown file format') FileFormat = 2; end end if FileFormat==0 [width,height,fps,startpos,NumberFrames] = readyuvheader(fid); end</pre> <pre lang="matlab">function [width,height,y]=readyseq(filename,start,stop) %******************************************************** % Function to load a bath yuv file % % Syntax : [width,height,ysequence] = readyseq(filename,start frame,end frame) % % NOTE: the frames are numbered from 0. % % A.N.Evans & N.Young % 5 June 2001 %******************************************************** %Note that I have to use some C functions here. I know some people dont like %mixing matlab with c, I'm affraid its un avoidable. %First we need to open the file [fid,msg] = fopen(filename,'r'); %if msg is longer than 0, i.e. it has something in it, we have an error if length(msg) > 0 disp('Error opening the file.'); else %read the header info [width,height,fps,startpos,NumberFrames] = readheader(fid); if start < NumberFrames & stop < NumberFrames %Now we can read the given frames. i=1; for frame = start:stop %now read the required frame y(i,:,:)=readyframe(fid,width,height,startpos,frame); i=i+1; end end end fclose(fid);</pre
-
-