
% Calculate TSE for all test sequences and write results intos a file 
% Open output file to write TSE values
fid = fopen('TE_packet_4.dat','wt');
if (fid == -1)
   error('The output file could not be opened.');
end
fprintf(fid, '%d\n', 7); % number of groups
 
% Output TSE for video v1
fprintf(fid, '%s\n', 'v1');
fprintf(fid, '%d\n', 13);

% Video v1 
tse(1) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I4.yuv',1280,720,'420','y'); % original
lineWrite(fid,'v1_1280x720_I4.yuv','\t%e',tse(1));
tse(2) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I4_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v1_1280x720_I4_pckErr1.yuv','\t%e',tse(2));
tse(3) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I4_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v1_1280x720_I4_pckErr2.yuv','\t%e',tse(3));
tse(4) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I4_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v1_1280x720_I4_pckErr3.yuv','\t%e',tse(4));
tse(5) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I4_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v1_1280x720_I4_pckErr4.yuv','\t%e',tse(5));

tse(6) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I8_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v1_1280x720_I8_pckErr1.yuv','\t%e',tse(6));
tse(7) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I8_pckErr2.yuv',1280,720,'420','y'); 
lineWrite(fid,'v1_1280x720_I8_pckErr2.yuv','\t%e',tse(7));
tse(8) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I8_pckErr3.yuv',1280,720,'420','y');
lineWrite(fid,'v1_1280x720_I8_pckErr3.yuv','\t%e',tse(8));
tse(9) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I8_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v1_1280x720_I8_pckErr4.yuv','\t%e',tse(9));

tse(10) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I12_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v1_1280x720_I12_pckErr1.yuv','\t%e',tse(10));
tse(11) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I12_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v1_1280x720_I12_pckErr2.yuv','\t%e',tse(11));
tse(12) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I12_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v1_1280x720_I12_pckErr3.yuv','\t%e',tse(12));
tse(13) = tseYUVvideo('v1_1280x720_I4.yuv','v1_1280x720_I12_pckErr4.yuv',1280,720,'420','y');
lineWrite(fid,'v1_1280x720_I12_pckErr4.yuv','\t%e',tse(13));

v1_tse=tse;

% Output TSE for video v7
fprintf(fid, '%s\n', 'v7');
fprintf(fid, '%d\n', 13);

tse(1) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I4.yuv',1280,720,'420','y'); % original
lineWrite(fid,'v7_1280x720_I4.yuv','\t%e',tse(1));
tse(2) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I4_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v7_1280x720_I4_pckErr1.yuv','\t%e',tse(2));
tse(3) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I4_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v7_1280x720_I4_pckErr2.yuv','\t%e',tse(3));
tse(4) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I4_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v7_1280x720_I4_pckErr3.yuv','\t%e',tse(4));
tse(5) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I4_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v7_1280x720_I4_pckErr4.yuv','\t%e',tse(5));

tse(6) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I8_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v7_1280x720_I8_pckErr1.yuv','\t%e',tse(6));
tse(7) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I8_pckErr2.yuv',1280,720,'420','y'); 
lineWrite(fid,'v7_1280x720_I8_pckErr2.yuv','\t%e',tse(7));
tse(8) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I8_pckErr3.yuv',1280,720,'420','y');
lineWrite(fid,'v7_1280x720_I8_pckErr3.yuv','\t%e',tse(8));
tse(9) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I8_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v7_1280x720_I8_pckErr4.yuv','\t%e',tse(9));

tse(10) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I12_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v7_1280x720_I12_pckErr1.yuv','\t%e',tse(10));
tse(11) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I12_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v7_1280x720_I12_pckErr2.yuv','\t%e',tse(11));
tse(12) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I12_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v7_1280x720_I12_pckErr3.yuv','\t%e',tse(12));
tse(13) = tseYUVvideo('v7_1280x720_I4.yuv','v7_1280x720_I12_pckErr4.yuv',1280,720,'420','y');
lineWrite(fid,'v7_1280x720_I12_pckErr4.yuv','\t%e',tse(13));

v7_tse=tse;

% Output TSE for video v8
fprintf(fid, '%s\n', 'v8');
fprintf(fid, '%d\n', 13);

tse(1) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I4.yuv',1280,720,'420','y'); % original
lineWrite(fid,'v8_1280x720_I4.yuv','\t%e',tse(1));
tse(2) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I4_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v8_1280x720_I4_pckErr1.yuv','\t%e',tse(2));
tse(3) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I4_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v8_1280x720_I4_pckErr2.yuv','\t%e',tse(3));
tse(4) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I4_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v8_1280x720_I4_pckErr3.yuv','\t%e',tse(4));
tse(5) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I4_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v8_1280x720_I4_pckErr4.yuv','\t%e',tse(5));

tse(6) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I8_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v8_1280x720_I8_pckErr1.yuv','\t%e',tse(6));
tse(7) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I8_pckErr2.yuv',1280,720,'420','y'); 
lineWrite(fid,'v8_1280x720_I8_pckErr2.yuv','\t%e',tse(7));
tse(8) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I8_pckErr3.yuv',1280,720,'420','y');
lineWrite(fid,'v8_1280x720_I8_pckErr3.yuv','\t%e',tse(8));
tse(9) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I8_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v8_1280x720_I8_pckErr4.yuv','\t%e',tse(9));

tse(10) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I12_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v8_1280x720_I12_pckErr1.yuv','\t%e',tse(10));
tse(11) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I12_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v8_1280x720_I12_pckErr2.yuv','\t%e',tse(11));
tse(12) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I12_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v8_1280x720_I12_pckErr3.yuv','\t%e',tse(12));
tse(13) = tseYUVvideo('v8_1280x720_I4.yuv','v8_1280x720_I12_pckErr4.yuv',1280,720,'420','y');
lineWrite(fid,'v8_1280x720_I12_pckErr4.yuv','\t%e',tse(13));

v8_tse=tse;

% Output TSE for video v9
fprintf(fid, '%s\n', 'v9');
fprintf(fid, '%d\n', 13);

tse(1) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I4.yuv',1280,720,'420','y'); % original
lineWrite(fid,'v9_1280x720_I4.yuv','\t%e',tse(1));
tse(2) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I4_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v9_1280x720_I4_pckErr1.yuv','\t%e',tse(2));
tse(3) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I4_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v9_1280x720_I4_pckErr2.yuv','\t%e',tse(3));
tse(4) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I4_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v9_1280x720_I4_pckErr3.yuv','\t%e',tse(4));
tse(5) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I4_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v9_1280x720_I4_pckErr4.yuv','\t%e',tse(5));

tse(6) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I8_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v9_1280x720_I8_pckErr1.yuv','\t%e',tse(6));
tse(7) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I8_pckErr2.yuv',1280,720,'420','y'); 
lineWrite(fid,'v9_1280x720_I8_pckErr2.yuv','\t%e',tse(7));
tse(8) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I8_pckErr3.yuv',1280,720,'420','y');
lineWrite(fid,'v9_1280x720_I8_pckErr3.yuv','\t%e',tse(8));
tse(9) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I8_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v9_1280x720_I8_pckErr4.yuv','\t%e',tse(9));

tse(10) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I12_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v9_1280x720_I12_pckErr1.yuv','\t%e',tse(10));
tse(11) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I12_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v9_1280x720_I12_pckErr2.yuv','\t%e',tse(11));
tse(12) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I12_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v9_1280x720_I12_pckErr3.yuv','\t%e',tse(12));
tse(13) = tseYUVvideo('v9_1280x720_I4.yuv','v9_1280x720_I12_pckErr4.yuv',1280,720,'420','y');
lineWrite(fid,'v9_1280x720_I12_pckErr4.yuv','\t%e',tse(13));

v9_tse=tse;

% Output TSE for video v10
fprintf(fid, '%s\n', 'v10');
fprintf(fid, '%d\n', 13);

tse(1) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I4.yuv',1280,720,'420','y'); % original
lineWrite(fid,'v10_1280x720_I4.yuv','\t%e',tse(1));
tse(2) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I4_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v10_1280x720_I4_pckErr1.yuv','\t%e',tse(2));
tse(3) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I4_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v10_1280x720_I4_pckErr2.yuv','\t%e',tse(3));
tse(4) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I4_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v10_1280x720_I4_pckErr3.yuv','\t%e',tse(4));
tse(5) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I4_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v10_1280x720_I4_pckErr4.yuv','\t%e',tse(5));

tse(6) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I8_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v10_1280x720_I8_pckErr1.yuv','\t%e',tse(6));
tse(7) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I8_pckErr2.yuv',1280,720,'420','y'); 
lineWrite(fid,'v10_1280x720_I8_pckErr2.yuv','\t%e',tse(7));
tse(8) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I8_pckErr3.yuv',1280,720,'420','y');
lineWrite(fid,'v10_1280x720_I8_pckErr3.yuv','\t%e',tse(8));
tse(9) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I8_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v10_1280x720_I8_pckErr4.yuv','\t%e',tse(9));

tse(10) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I12_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v10_1280x720_I12_pckErr1.yuv','\t%e',tse(10));
tse(11) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I12_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v10_1280x720_I12_pckErr2.yuv','\t%e',tse(11));
tse(12) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I12_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v10_1280x720_I12_pckErr3.yuv','\t%e',tse(12));
tse(13) = tseYUVvideo('v10_1280x720_I4.yuv','v10_1280x720_I12_pckErr4.yuv',1280,720,'420','y');
lineWrite(fid,'v10_1280x720_I12_pckErr4.yuv','\t%e',tse(13));

v10_tse=tse;

% Output TSE for video v11
fprintf(fid, '%s\n', 'v11');
fprintf(fid, '%d\n', 13);

tse(1) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I4.yuv',1280,720,'420','y'); % original
lineWrite(fid,'v11_1280x720_I4.yuv','\t%e',tse(1));
tse(2) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I4_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v11_1280x720_I4_pckErr1.yuv','\t%e',tse(2));
tse(3) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I4_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v11_1280x720_I4_pckErr2.yuv','\t%e',tse(3));
tse(4) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I4_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v11_1280x720_I4_pckErr3.yuv','\t%e',tse(4));
tse(5) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I4_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v11_1280x720_I4_pckErr4.yuv','\t%e',tse(5));

tse(6) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I8_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v11_1280x720_I8_pckErr1.yuv','\t%e',tse(6));
tse(7) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I8_pckErr2.yuv',1280,720,'420','y'); 
lineWrite(fid,'v11_1280x720_I8_pckErr2.yuv','\t%e',tse(7));
tse(8) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I8_pckErr3.yuv',1280,720,'420','y');
lineWrite(fid,'v11_1280x720_I8_pckErr3.yuv','\t%e',tse(8));
tse(9) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I8_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v11_1280x720_I8_pckErr4.yuv','\t%e',tse(9));

tse(10) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I12_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v11_1280x720_I12_pckErr1.yuv','\t%e',tse(10));
tse(11) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I12_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v11_1280x720_I12_pckErr2.yuv','\t%e',tse(11));
tse(12) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I12_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v11_1280x720_I12_pckErr3.yuv','\t%e',tse(12));
tse(13) = tseYUVvideo('v11_1280x720_I4.yuv','v11_1280x720_I12_pckErr4.yuv',1280,720,'420','y');
lineWrite(fid,'v11_1280x720_I12_pckErr4.yuv','\t%e',tse(13));

v11_tse=tse;

% Output TSE for video v12
fprintf(fid, '%s\n', 'v12');
fprintf(fid, '%d\n', 13);

tse(1) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I4.yuv',1280,720,'420','y'); % original
lineWrite(fid,'v12_1280x720_I4.yuv','\t%e',tse(1));
tse(2) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I4_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v12_1280x720_I4_pckErr1.yuv','\t%e',tse(2));
tse(3) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I4_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v12_1280x720_I4_pckErr2.yuv','\t%e',tse(3));
tse(4) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I4_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v12_1280x720_I4_pckErr3.yuv','\t%e',tse(4));
tse(5) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I4_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v12_1280x720_I4_pckErr4.yuv','\t%e',tse(5));

tse(6) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I8_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v12_1280x720_I8_pckErr1.yuv','\t%e',tse(6));
tse(7) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I8_pckErr2.yuv',1280,720,'420','y'); 
lineWrite(fid,'v12_1280x720_I8_pckErr2.yuv','\t%e',tse(7));
tse(8) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I8_pckErr3.yuv',1280,720,'420','y');
lineWrite(fid,'v12_1280x720_I8_pckErr3.yuv','\t%e',tse(8));
tse(9) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I8_pckErr4.yuv',1280,720,'420','y'); 
lineWrite(fid,'v12_1280x720_I8_pckErr4.yuv','\t%e',tse(9));

tse(10) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I12_pckErr1.yuv',1280,720,'420','y'); 
lineWrite(fid,'v12_1280x720_I12_pckErr1.yuv','\t%e',tse(10));
tse(11) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I12_pckErr2.yuv',1280,720,'420','y');
lineWrite(fid,'v12_1280x720_I12_pckErr2.yuv','\t%e',tse(11));
tse(12) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I12_pckErr3.yuv',1280,720,'420','y'); 
lineWrite(fid,'v12_1280x720_I12_pckErr3.yuv','\t%e',tse(12));
tse(13) = tseYUVvideo('v12_1280x720_I4.yuv','v12_1280x720_I12_pckErr4.yuv',1280,720,'420','y');
lineWrite(fid,'v12_1280x720_I12_pckErr4.yuv','\t%e',tse(13));

v12_tse=tse;

save tse_videos_3;
fclose(fid)