summaryrefslogtreecommitdiffstats
path: root/libmpcodecs
diff options
context:
space:
mode:
authorrguyom <rguyom@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-04-06 23:37:56 +0000
committerrguyom <rguyom@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-04-06 23:37:56 +0000
commita19559f911411665afe3fb106486cf4dfbecb360 (patch)
tree94af7b5fffced02aa3329e58772b2ed1f1b68719 /libmpcodecs
parentdae951d466af113a15cc7da1100a101b96e5058e (diff)
downloadmpv-a19559f911411665afe3fb106486cf4dfbecb360.tar.bz2
mpv-a19559f911411665afe3fb106486cf4dfbecb360.tar.xz
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9866 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpcodecs')
-rw-r--r--libmpcodecs/vd_ffmpeg.c26
-rw-r--r--libmpcodecs/ve_lavc.c17
2 files changed, 38 insertions, 5 deletions
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c
index a14c4cd1b6..864ae1f1a3 100644
--- a/libmpcodecs/vd_ffmpeg.c
+++ b/libmpcodecs/vd_ffmpeg.c
@@ -550,6 +550,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
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 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
}
}
+ // 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 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
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;
}
diff --git a/libmpcodecs/ve_lavc.c b/libmpcodecs/ve_lavc.c
index b7e79a4ed4..8149dbf257 100644
--- a/libmpcodecs/ve_lavc.c
+++ b/libmpcodecs/ve_lavc.c
@@ -528,6 +528,7 @@ static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
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 @@ static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
/*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),