function batch_ffmpeg_yuv(txt, W, H, metric)
% Script for batch evaluating luma YUV files.
% batch_vqeg_yuv(txt, W, H, metric),
% where 'txt' is the name of a file containing filenames of processed
% files, W and H are width and height respectively and
% switch 'metric' allows you to choose between 'g' od 'G' for GBIM metric
% and 'm' or 'M' for Marziliano's Perceived Blur metric.
% For luma YUV files only.
% Created: April, 2013. Ondrej Zach.

if strcmp(metric, 'g') | strcmp(metric, 'G')
    disp('Chosen metric is GBIM')
elseif strcmp(metric, 'm')  | strcmp(metric, 'M')
       disp('Chosen metric is Marziliano')
    else disp('Unknown metric identifier.')
        return
end

list_of_files=char(textread(txt, '%s'));
fclose('all');
nFiles=size(list_of_files, 1);

disp('Computation started.')
disp('Current file:')



for i=1:nFiles
    disp(list_of_files(i,:))
    file=list_of_files(i,:);
    fid=fopen(file);
    if fid==-1;
        s=sprintf('File %s does not exist. Trying next file in the list.', file);
        disp(s)
    else
    Ytemp=fread(fid, '*uint8');
    fclose(fid);
    nFrames=length(Ytemp)/(W*H);
    Y=reshape(Ytemp, W,H,nFrames);
    Y=permute(Y, [2 1 3]);
   
    if H==486
        Y=Y(1:480,:,:);    % the number of rows must be a multiple of 8.
    else
     ;
    end
    clear Ytemp
    disp('File loaded.')
    
    if strcmp(metric, 'g')  | strcmp(metric, 'G')
    resultGBIM(i,:)=GBIM(Y, 8, nFrames);
    disp(mean(resultGBIM(i,:)))
    results_file_name=sprintf('%s_GBIM.csv', list_of_files(i,:));
    csvwrite(results_file_name, resultGBIM(i,:));   
    
    else disp(nFrames)
        for k=1:nFrames
     resultMarz_each(1,k)=marziliano(Y(:,:,k), H, W); %saving value of Marz. metric for each frame
    end
%     disp(mean(resultMarz_each))
    results_file_name=sprintf('%s_Marz.csv', list_of_files(i,:));
    csvwrite(results_file_name, resultMarz_each);
    resultMarz(i,:)=resultMarz_each;
    end
       
    
    end
end


if strcmp(metric, 'g')  | strcmp(metric, 'G')
    disp('Chosen metric is GBIM')
    complete_res=sprintf('%s_GBIM.csv', txt(1:end-4));
    csvwrite(complete_res, resultGBIM);
    
else
     complete_res=sprintf('%s_Marz.csv', txt(1:end-4));
    csvwrite(complete_res, resultMarz);
end

disp('Computation finished.')