changeset 9865:30893b593947

Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
author rguyom
date Sun, 06 Apr 2003 23:37:56 +0000
parents b65bcfaedbe5
children c67a4723b74c
files libmpcodecs/vd_ffmpeg.c libmpcodecs/ve_lavc.c
diffstat 2 files changed, 38 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vd_ffmpeg.c	Sun Apr 06 22:01:54 2003 +0000
+++ b/libmpcodecs/vd_ffmpeg.c	Sun Apr 06 23:37:56 2003 +0000
@@ -550,6 +550,7 @@
         static int frame_number=0;
         static double all_frametime=0.0;
         AVFrame *pic= avctx->coded_frame;
+	double quality=0.0;
 
         if(!fvstats) {
             time_t today2;
@@ -567,10 +568,24 @@
             }
         }
 
+	// average MB quantizer
+	{
+	    int x, y;
+	    int w = (avctx->width+15) >> 4;
+	    int h = (avctx->height+15) >> 4;
+	    int8_t *q = pic->qscale_table;
+	    for( y = 0; y < h; y++ ) {
+		for( x = 0; x < w; x++ )
+		    quality += (double)*(q+x);
+		q += pic->qstride;
+	    }
+	    quality /= w * h;
+	}
+
         all_len+=len;
         all_frametime+=sh->frametime;
         fprintf(fvstats, "frame= %5d q= %2.2f f_size= %6d s_size= %8.0fkB ",
-            ++frame_number, pic->quality, len, (double)all_len/1024);
+            ++frame_number, quality, len, (double)all_len/1024);
         fprintf(fvstats, "time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
            all_frametime, (double)(len*8)/sh->frametime/1000.0,
            (double)(all_len*8)/all_frametime/1000.0);
@@ -587,11 +602,14 @@
 	case FF_B_TYPE:
             fprintf(fvstats, "type= B\n");
 	    break;
+	default:
+            fprintf(fvstats, "type= ? (%d)\n", pic->pict_type);
+	    break;
 	}
         
-        ctx->qp_stat[(int)(pic->quality+0.5)]++;
-        ctx->qp_sum += pic->quality;
-        ctx->inv_qp_sum += 1.0/pic->quality;
+        ctx->qp_stat[(int)(quality+0.5)]++;
+        ctx->qp_sum += quality;
+        ctx->inv_qp_sum += 1.0/(double)quality;
         
         break;
     }
--- a/libmpcodecs/ve_lavc.c	Sun Apr 06 22:01:54 2003 +0000
+++ b/libmpcodecs/ve_lavc.c	Sun Apr 06 23:37:56 2003 +0000
@@ -528,6 +528,7 @@
         static double all_frametime=0.0;
         AVFrame *pic= lavc_venc_context->coded_frame;
         double f= lavc_venc_context->width*lavc_venc_context->height*255.0*255.0;
+	double quality=0.0;
 
         if(!fvstats) {
             time_t today2;
@@ -543,10 +544,24 @@
                 /*exit(1);*/
             }
         }
+	
+	// average MB quantizer
+	{
+	    int x, y;
+	    int w = (lavc_venc_context->width+15) >> 4;
+	    int h = (lavc_venc_context->height+15) >> 4;
+	    int8_t *q = lavc_venc_context->coded_frame->qscale_table;
+	    for( y = 0; y < h; y++ ) {
+		for( x = 0; x < w; x++ )
+		    quality += (double)*(q+x);
+		q += lavc_venc_context->coded_frame->qstride;
+	    }
+	    quality /= w * h;
+	}
 
         fprintf(fvstats, "%6d, %2.2f, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n",
             lavc_venc_context->coded_frame->coded_picture_number,
-            lavc_venc_context->coded_frame->quality,
+            quality,
             out_size,
             psnr(lavc_venc_context->coded_frame->error[0]/f),
             psnr(lavc_venc_context->coded_frame->error[1]*4/f),