[xiph-commits] r18223 - trunk/theora/lib
gmaxwell at svn.xiph.org
gmaxwell at svn.xiph.org
Sat Mar 31 11:49:57 PDT 2012
Author: gmaxwell
Date: 2012-03-31 11:49:57 -0700 (Sat, 31 Mar 2012)
New Revision: 18223
Modified:
trunk/theora/lib/encint.h
trunk/theora/lib/rate.c
Log:
Save activity from first pass. Gives a small SSIM improvement (e.g. 0.04dB for 360p elephants dream at 750kbit/s)
Modified: trunk/theora/lib/encint.h
===================================================================
--- trunk/theora/lib/encint.h 2012-03-25 15:58:18 UTC (rev 18222)
+++ trunk/theora/lib/encint.h 2012-03-31 18:49:57 UTC (rev 18223)
@@ -524,6 +524,8 @@
unsigned dup_count:31;
/*The frame type from pass 1.*/
unsigned frame_type:1;
+ /*The frame activity average from pass 1.*/
+ unsigned activity_avg;
};
Modified: trunk/theora/lib/rate.c
===================================================================
--- trunk/theora/lib/rate.c 2012-03-25 15:58:18 UTC (rev 18222)
+++ trunk/theora/lib/rate.c 2012-03-31 18:49:57 UTC (rev 18223)
@@ -762,6 +762,7 @@
_enc->rc.cur_metrics.log_scale=oc_q57_to_q24(log_scale);
_enc->rc.cur_metrics.dup_count=_enc->dup_count;
_enc->rc.cur_metrics.frame_type=_enc->state.frame_type;
+ _enc->rc.cur_metrics.activity_avg=_enc->activity_avg;
_enc->rc.twopass_buffer_bytes=0;
}break;
case 2:{
@@ -864,9 +865,9 @@
return dropped;
}
-#define OC_RC_2PASS_VERSION (1)
+#define OC_RC_2PASS_VERSION (2)
#define OC_RC_2PASS_HDR_SZ (38)
-#define OC_RC_2PASS_PACKET_SZ (8)
+#define OC_RC_2PASS_PACKET_SZ (12)
static void oc_rc_buffer_val(oc_rc_state *_rc,ogg_int64_t _val,int _bytes){
while(_bytes-->0){
@@ -901,6 +902,7 @@
oc_rc_buffer_val(&_enc->rc,
_enc->rc.cur_metrics.dup_count|_enc->rc.cur_metrics.frame_type<<31,4);
oc_rc_buffer_val(&_enc->rc,_enc->rc.cur_metrics.log_scale,4);
+ oc_rc_buffer_val(&_enc->rc,_enc->rc.cur_metrics.activity_avg,4);
}
}
else if(_enc->packet_state==OC_PACKET_DONE&&
@@ -1051,16 +1053,19 @@
if(_enc->rc.twopass_buffer_fill>=OC_RC_2PASS_PACKET_SZ){
ogg_uint32_t dup_count;
ogg_int32_t log_scale;
+ unsigned activity;
int qti;
int arg;
/*Read the metrics for the next frame.*/
dup_count=oc_rc_unbuffer_val(&_enc->rc,4);
log_scale=oc_rc_unbuffer_val(&_enc->rc,4);
+ activity=oc_rc_unbuffer_val(&_enc->rc,4);
_enc->rc.cur_metrics.log_scale=log_scale;
qti=(dup_count&0x80000000)>>31;
_enc->rc.cur_metrics.dup_count=dup_count&0x7FFFFFFF;
_enc->rc.cur_metrics.frame_type=qti;
_enc->rc.twopass_force_kf=qti==OC_INTRA_FRAME;
+ _enc->activity_avg=_enc->rc.cur_metrics.activity_avg=activity;
/*"Helpfully" set the dup count back to what it was in pass 1.*/
arg=_enc->rc.cur_metrics.dup_count;
th_encode_ctl(_enc,TH_ENCCTL_SET_DUP_COUNT,&arg,sizeof(arg));
@@ -1088,9 +1093,11 @@
ogg_uint32_t dup_count;
ogg_int32_t log_scale;
int qti;
+ unsigned activity;
/*Read the metrics for the next frame.*/
dup_count=oc_rc_unbuffer_val(&_enc->rc,4);
log_scale=oc_rc_unbuffer_val(&_enc->rc,4);
+ activity=oc_rc_unbuffer_val(&_enc->rc,4);
/*Add the to the circular buffer.*/
fmi=_enc->rc.frame_metrics_head+_enc->rc.nframe_metrics++;
if(fmi>=_enc->rc.cframe_metrics)fmi-=_enc->rc.cframe_metrics;
@@ -1099,6 +1106,7 @@
qti=(dup_count&0x80000000)>>31;
m->dup_count=dup_count&0x7FFFFFFF;
m->frame_type=qti;
+ m->activity_avg=activity;
/*And accumulate the statistics over the window.*/
_enc->rc.nframes[qti]++;
_enc->rc.nframes[2]+=m->dup_count;
@@ -1125,6 +1133,7 @@
*(_enc->rc.frame_metrics+_enc->rc.frame_metrics_head);
_enc->rc.twopass_force_kf=
_enc->rc.cur_metrics.frame_type==OC_INTRA_FRAME;
+ _enc->activity_avg=_enc->rc.cur_metrics.activity_avg;
/*"Helpfully" set the dup count back to what it was in pass 1.*/
arg=_enc->rc.cur_metrics.dup_count;
th_encode_ctl(_enc,TH_ENCCTL_SET_DUP_COUNT,&arg,sizeof(arg));
More information about the commits
mailing list