summaryrefslogtreecommitdiff
path: root/yuvtool/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'yuvtool/main.c')
-rw-r--r--yuvtool/main.c133
1 files changed, 117 insertions, 16 deletions
diff --git a/yuvtool/main.c b/yuvtool/main.c
index 964d54f..1e7e3a7 100644
--- a/yuvtool/main.c
+++ b/yuvtool/main.c
@@ -47,6 +47,7 @@
#include <sys/shm.h>
#include <sys/time.h>
#include <assert.h>
+#include <errno.h>
#include <../utils/va_wrapper.h>
#include <../utils/loadsurface_yuv.h>
@@ -71,6 +72,7 @@ static int frame_rate=30,frame_num=1;
static struct timeval tftarget;
static int output_psnr_file = 0;
static int rotate_degree = 90;
+static int psnr_each_frame = 0;
static int GetPortId(Display *dpy)
{
@@ -736,16 +738,18 @@ static int rotate_yuv(void)
static int exit_with_help(void)
{
- printf("yuvtool <display|convert|psnr|ssim|create|rotate> <options>\n");
+ printf("yuvtool <display|convert|psnr|ssim|create|rotate|md5> <options>\n");
printf(" for display, options is: -s <widthxheight> -i <input YUV file> -ifourcc <input fourcc> -path <output path>\n");
printf(" for create, options is: -s <widthxheight> -n <frame number> -i <input YUV file> -ifourcc <input fourcc>\n");
printf(" for convert, options is: -s <widthxheight> -i <input YUV file> -ifourcc <input fourcc>\n");
printf(" -o <output YUV file> -ofourcc <output fourcc>\n");
printf(" currently, support NV12<->I420/YV12 BMP->NV12 conversion\n");
- printf(" for psnr, options is: -s <widthxheight> -i <input YUV file> -o <output YUV file> -n <frame number>\n");
+ printf(" for psnr, options is: -s <widthxheight> -i <input YUV file> -o <output YUV file> -n <frame number> -e\n");
printf(" The two files should be same with width same FOURCC and resolution\n");
+ printf(" -e will calculate each frame psnr\n");
printf(" for ssim, options is: -s <widthxheight> -i <reference YUV file> -o <reconstructed YUV file> -n <frame number>\n");
- printf(" The two files should be same with width same FOURCC and resolution\n");
+ printf(" for md5, options is: -s <widthxheight> -i <reference YUV file> -ifourcc <input fourcc>\n");
+ printf(" Calculate the MD5 of each frame for static frame analyze\n");
printf(" for crc, options is:-s widthxheight -i <input YUV file>\n");
printf(" for scale, options is:-s widthxheight -i <input YUV file> -ifourcc <input fourcc> \n");
printf(" -S widthxheight -o <output YUV file>\n");
@@ -789,14 +793,32 @@ static int psnr_yuv(void)
{
double psnr = 0, mse = 0;
double psnr_y, psnr_u, psnr_v;
-
+ int i;
+
fprintf(stdout,"Calculate PSNR %s vs %s, (%dx%d, %d frames)\n",
input_fn, output_fn, width, height, frame_num);
- calc_PSNR(input_fp, output_fp, width, height, frame_num,
- &psnr, &psnr_y, &psnr_u, &psnr_v, &mse);
+
+ if (psnr_each_frame == 0) {
+ calc_PSNR(input_fp, output_fp, width, height, frame_num,
+ &psnr, &psnr_y, &psnr_u, &psnr_v, &mse);
+
+ printf("PSNR: %.2f (Y=%.2f,U=%.2f, V=%.2f)\n", psnr, psnr_y, psnr_u, psnr_v);
+ return 0;
+ }
+
+
+ for (i=0; i<frame_num; i++) {
+ psnr_y = psnr_u = psnr_v = psnr = mse = 0;
+ calc_PSNR(input_fp, output_fp, width, height, 1,
+ &psnr, &psnr_y, &psnr_u, &psnr_v, &mse);
+ fseek(input_fp, width*height*1.5, SEEK_CUR);
+ fseek(output_fp, width*height*1.5, SEEK_CUR);
+
+ printf("Frame %d: PSNR: %.2f (Y=%.2f,U=%.2f, V=%.2f)\n", i, psnr, psnr_y, psnr_u, psnr_v);
- printf("PSNR: %.2f (Y=%.2f,U=%.2f, V=%.2f\n", psnr, psnr_y, psnr_u, psnr_v);
+ }
+
return 0;
}
@@ -816,6 +838,78 @@ static int ssim_yuv(void)
}
+static int md5_yuv(void)
+{
+ unsigned int frame_size = width * height * 1.5;
+ char tmp_template[32] = { 'm', 'd', '5', 'X','X','X','X','X','X' };
+ char *tmp_fn, *one_frame, popen_cmd[64];
+ FILE *tmp_fp;
+ int current_frame = 0;
+
+ fprintf(stdout, "Calculate each frame MD5, (%dx%d, %d frames)\n",
+ width, height, frame_num);
+
+ tmp_fn = mktemp(tmp_template);
+ tmp_fp = fopen(tmp_fn, "w+");
+ if (tmp_fp == NULL) {
+ printf("Open temp file %s failed (%s)\n", tmp_fn, strerror(errno));
+ exit(1);
+ }
+
+ one_frame = malloc(frame_size);
+ if (one_frame == NULL) {
+ printf("malloc error %s, exit\n", strerror(errno));
+ exit(1);
+ }
+
+ sprintf(popen_cmd, "md5sum %s", tmp_fn);
+ while (frame_num-- > 0) {
+ char last_md5sum_output[256];
+ char md5sum_output[256];
+
+ FILE *popen_fp;
+ int i;
+
+ fread(one_frame, frame_size, 1, input_fp);
+
+ rewind(tmp_fp);
+ fwrite(one_frame, frame_size, 1, tmp_fp);
+ fflush(tmp_fp);
+ fsync(fileno(tmp_fp));
+
+ popen_fp = popen(popen_cmd, "r");
+ if (popen_fp == NULL) {
+ printf("Failed to md5sum command\n" );
+ exit(1);
+ }
+ fgets(md5sum_output, sizeof(md5sum_output), popen_fp);
+ pclose(popen_fp);
+
+ printf("Frame %d md5: ", current_frame);
+
+ for (i=0; i<sizeof(md5sum_output); i++) {
+ if (md5sum_output[i] == ' ')
+ md5sum_output[i] = '\0';
+ }
+ if ((current_frame > 0) &&
+ (strcmp(md5sum_output, last_md5sum_output) == 0))
+ printf("***identicle***");
+ else
+ printf(md5sum_output);
+
+ current_frame ++;
+ strcpy(last_md5sum_output, md5sum_output);
+
+ printf("\n");
+ }
+
+ free(one_frame);
+ fclose(tmp_fp);
+
+ return 0;
+}
+
+
static int scale_yuv(void)
{
int tmp=0,i=0;
@@ -932,22 +1026,22 @@ static int YUV_Generator_Planar(int width, int height,
unsigned char *Y_start, int Y_pitch,
unsigned char *U_start, int U_pitch,
unsigned char *V_start, int V_pitch,
- int UV_interleave)
+ unsigned int fourcc)
{
static int row_shift = 0;
int box_width = 8;
- row_shift++;
if (row_shift == 16) row_shift = 0;
- V_start = U_start + 1;
yuvgen_planar(width, height,
Y_start, Y_pitch,
U_start, U_pitch,
V_start, V_pitch,
- VA_FOURCC_NV12, box_width, row_shift,
+ fourcc, box_width, row_shift,
0);
+ row_shift++;
+
return 0;
}
@@ -969,7 +1063,7 @@ static int create_yuv(void)
one_frame, width,
one_frame + width*height, width/2,
one_frame + width*height + (width/2)*(height/2), width/2,
- 0);
+ ifourcc);
fwrite(one_frame, width*height*1.5, 1, input_fp);
}
} else if ((ifourcc == VA_FOURCC_YV12)) {
@@ -978,7 +1072,7 @@ static int create_yuv(void)
one_frame, width,
one_frame + width*height + (width/2)*(height/2), width/2,
one_frame + width*height, width/2,
- 0);
+ ifourcc);
fwrite(one_frame, width*height*1.5, 1, input_fp);
}
} else if (ifourcc == VA_FOURCC_NV12) {
@@ -987,7 +1081,7 @@ static int create_yuv(void)
one_frame, width,
one_frame + width*height, width,
one_frame + width*height, width,
- 1);
+ ifourcc);
fwrite(one_frame, width*height*1.5, 1, input_fp);
}
} else {
@@ -1007,7 +1101,8 @@ static enum {
SSIM,
CREATE,
SCALE,
- ROTATE
+ ROTATE,
+ MD5
} operation;
@@ -1047,6 +1142,8 @@ int main(int argc, char **argv)
operation = SCALE;
else if (strcmp(argv[1],"rotate") == 0)
operation = ROTATE;
+ else if (strcmp(argv[1],"md5") == 0)
+ operation = MD5;
else {
printf("ERROR:The first parameter isn't <scale|display|convert|psnr|create|crc>, exit\n");
exit_with_help();
@@ -1056,7 +1153,7 @@ int main(int argc, char **argv)
argc--;
argv++;
- while ((c=getopt_long_only(argc,argv,"fn:s:S:i:d:o:h?",long_opts,&long_index)) != -1) {
+ while ((c=getopt_long_only(argc,argv,"fen:s:S:i:d:o:h?",long_opts,&long_index)) != -1) {
switch (c) {
case 'h':
case '?':
@@ -1066,6 +1163,9 @@ int main(int argc, char **argv)
case 'f':
output_psnr_file = 1;
break;
+ case 'e':
+ psnr_each_frame = 1;
+ break;
case 'n':
input_frame_num = atoi(optarg);
break;
@@ -1188,6 +1288,7 @@ int main(int argc, char **argv)
if (operation == ROTATE) rotate_yuv();
if (operation == PSNR) psnr_yuv();
if (operation == SSIM) ssim_yuv();
+ if (operation == MD5) md5_yuv();
if (operation == CONVERT && ifourcc == VA_FOURCC_BMP24)
bmp2yuv(input_fp, output_fp, ofourcc);
else if (operation == CONVERT)