fclose all; clear all; close all;

nframes = 500;
strength = [2] ;
qps = 6;
%camera = [1 2 3 4 5 6 7 8];
original = [11]; % number of originals (7 in the experiment)
prob2 = [1 3 7]; % Corresponde a porcentagem fixa de erros com rand(1) para 12 pacotes;
npacotesPorFrame = 8; 
ACK_frame = [12] ; %DO NOT  CHANGE
w_file1 = 'none';
position_err = 3;

w = 1280;
h = 720;

%PARTE 1 % O codificador nao leva em consideracao os erros
for ncam = 1:1:length(original) % number of originals
    for nack = 1:1:length(ACK_frame) 
        for str = 1:1:length(strength) % strengths of artifacts
            nqps = [1:1:length(qps)];
            % original names example: blkblr_v1_1280x720_I4_0.yuv (I4 does
            % not mean anything.
            seq_orig1 = ['./Results/blkblr_v' num2str(original(ncam)) '_1280x720_I4_' num2str(strength(str)) '.yuv'];
            
            rec_out1 = [seq_orig1(1:end-19) '_I' num2str(ACK_frame(nack)) '_' num2str(strength(str)) '.yuv'];
            bin_out1 = [seq_orig1(1:end-19) '_I' num2str(ACK_frame(nack)) '_' num2str(strength(str)) '.264'];
            %H264_Original\JM\bin\lencod
            
            system(['./jm_18.2/bin/lencod.exe -d ./jm_18.2/bin/encoder_color.cfg -p InputFile="' seq_orig1 '" -p FramesToBeEncoded=' num2str(nframes) ' -p SourceWidth=' num2str(w) ' -p SourceHeight=' num2str(h)...
                ' -p OutputWidth=' num2str(w) ' -p OutputHeight=' num2str(h) ' -p ReconFile="' rec_out1 '" -p OutputFile="' bin_out1 '" -p QPISlice='  num2str(qps(nqps))...
                ' -p QPPSlice=' num2str(qps(nqps)) ' -p NumberReferenceFrames=1 -p SliceMode=1 -p SliceArgument=' num2str(((w*h)/(16*16))/npacotesPorFrame) ' -p IntraPeriod=' num2str(ACK_frame(nack))]);
            
            % Parte 3: Gera erros
%             for nprob = 1:1:length(prob2)
%                 bin_out1Err = [bin_out1(1:end-4) '_pckErr' num2str(nprob) '.264'];
%                 
%                 %Erros distribuidos
%                 system(['ErrorGen\Release\NalTools3 -o' bin_out1Err ' ' bin_out1 ':0:' num2str(npacotesPorFrame-1) %' ' bin_out1 ':'  num2str((prob2(nprob))) ':' num2str(npacotesPorFrame) ':' num2str(npacotesPorFrame*ACK_frame%%%(nack)) ':' num2str(npacotesPorFrame*nframes)]);
%                 
%                                 
%                 %   Parte 4.5: Decodifica
%                 system(['H264_Decodificar\bin\ldecod -i ' bin_out1Err ' -o ' bin_out1Err(1:end-4) '.yuv']);
%                 
%             end
            
        end
    end
end

