function PSNR=xml2psnr_batch(txt, W, H)
% Script for batch PSNR estimation for
% MPEG 4 AVC coded videos.
% PSNR = xml2psnr_batch(txt, W, H), where
% txt specifies the input text files containig videos
% filenames and W and H are resolution of the video.
% ldecod.exe needed to run this function.
% Created: May, 2013. Ondrej Zach.

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

for i=1:nFiles
file=list_of_files(i,:);
disp(file)
[status results]=system(sprintf('ldecod -i %s -xmltrace trace.xml', file));
if status==0
PSNR(i)=xml2psnr('trace.xml', W, H);
disp(PSNR(i))
else disp('File cannot be opened or ldecod not available.')
end
end
csvwrite('psnr.csv', PSNR);


    