#include
#include
#define MAXPACKETSIZE 50000 //Ìegethos paketon
//Dimiourgia PACKET LOSS pou kathorizetai apo to arxeio error
int looseit(FILE *err){
int c;
do {
c = getc (err);
if (c == EOF) {
fseek(err, 0, SEEK_SET);
}
else if (c == '0') return 1;
else return 0;
} while (1);
}
int main(){
FILE *in, *out, *err0=NULL;
unsigned char buf[MAXPACKETSIZE];
unsigned char nal_type;
int i;
int packet_number=0;
char command_line[1000];
printf("Starting video encoding!\n");
printf("\n\n Please Wait!!! \n\n");
//Kodikopoihsh tou video foreman_cif.yuv kai paragogi tou BINARY FILE hevc.bin
sprintf(command_line,"%s","TAppEncoder.exe -c cfg\\encoder_randomaccess_main.cfg -q 26 -fr 30 -wdt 352 -hgt 288 -f 300 -i foreman_cif.yuv -b hevc.bin");
system(command_line);
printf("End of video encoding!\n");
printf("Starting video transmition \n\n");
printf("A number of packets are going to be lost!!! \n\n");
printf("\n\n Please Wait!!! \n\n");
if (NULL == (in = fopen("rec.yuv","rb"))) {
perror("Cannot read input binary file that generated by the video file!");
exit(1);
}
if (NULL == (out = fopen("hevc_loss.yuv","wb"))) {
perror("Cannot open destination binary file with errors");
exit(2);
}
if (NULL == (err0 = fopen ("error", "rb"))) {
perror ("Cannot open error pattern file");
exit (3);
}
//Dimiourgia sfalmaton sto binary file
buf[0]=fgetc(in);
buf[1]=fgetc(in);
buf[2]=fgetc(in);
buf[3]=fgetc(in);
buf[4] = fgetc(in);
nal_type = buf[4] & 0x0F;
for(i=5; ; i++)
{
buf = fgetc(in);
if(feof(in)==0)
{
if(buf[i-3]==0 && buf[i-2]==0 && buf[i-1]==0 && buf==1)
{
fwrite(buf, sizeof(unsigned char), i-3, out);
packet_number++;
fflush(out);
buf[0]=buf[i-3];
buf[1]=buf[i-2];
buf[2]=buf[i-1];
buf[3]=buf;
break;
}
}
}
while(feof(in)==0)
{
for(i=4; ;i++)
{
buf = fgetc(in);
nal_type = buf[4] & 0x1F;
if(feof(in)==0)
{
if(buf[i-3]==0 && buf[i-2]==0 && buf[i-1]==0 && buf==1 )
{
if(nal_type==1 || nal_type==20)
{
if(err0 != NULL && looseit(err0)){
}
else
{
fwrite(buf, sizeof(unsigned char), i-3, out);
fflush(out);
}
}
else
{
fwrite(buf, sizeof(unsigned char), i-3, out);
fflush(out);
}
packet_number++;
buf[0]=buf[i-3];
buf[1]=buf[i-2];
buf[2]=buf[i-1];
buf[3]=buf;
break;
}
}
else
{
fwrite(buf, sizeof(unsigned char), i, out);
fflush(out);
break;
}
}
}
fclose(in);
fclose(out);
if ( err0)
fclose(err0);
printf("End of transmition!!!\n\n");
printf("Starting video decoding\n\n");
printf("\n\n Please Wait!!! \n\n");
sprintf(command_line,"%s","TAppDecoder.exe -b hevc_loss.bin -o foreman_cif_loss.yuv");
system(command_line);
printf("End of video decoding!!!\n\n");
return 0;
}
How to encode and decode instead of foreman the yuv :soccer_704x576_60_orig_02_yuv.zip186272 kb, 60 fig. per second, using the previous code (hevc) ? and how to evaluate the psnr for the decoded yuv for 2 different profiles of HEVC random Access (RA-HE) & (RA-LC) and various BER (10^-4, 10^-5,10^-6)?
0.42dB RAHE(random access high efficiency) 0.44dB RA LC (random access low complexity)
- - - - - - - - - -
http://www.sunrayimage.com/yuvanalyzer_psnr.html for the psnr