aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Massiot2005-02-02 18:49:04 +0000
committerMichael Niedermayer2005-02-02 18:49:04 +0000
commit957c743a23881636dcc1da307ad9c4ac6b65f7ac (patch)
treecae7538bce03ce319f09862e58576a4af094dfce
parentebaa7e03154e4bec5cbeb7dc839980c67b64c436 (diff)
Border processing adaptive quant patch by (Christophe Massiot |cmassiot freebox fr)
Originally committed as revision 3927 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/avcodec.h10
-rw-r--r--libavcodec/mpegvideo.c1
-rw-r--r--libavcodec/ratecontrol.c24
3 files changed, 34 insertions, 1 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 85b94425f9..ebb27e536c 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -17,7 +17,7 @@ extern "C" {
#define FFMPEG_VERSION_INT 0x000409
#define FFMPEG_VERSION "0.4.9-pre1"
-#define LIBAVCODEC_BUILD 4740
+#define LIBAVCODEC_BUILD 4741
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION
@@ -1750,6 +1750,14 @@ typedef struct AVCodecContext {
* - decoding: unused
*/
int frame_skip_cmp;
+
+ /**
+ * border processing masking. raises the quantizer for mbs on the borders
+ * of the picture.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ float border_masking;
} AVCodecContext;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index bca63a1913..5049b696c3 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -949,6 +949,7 @@ int MPV_encode_init(AVCodecContext *avctx)
|| s->avctx->temporal_cplx_masking
|| s->avctx->spatial_cplx_masking
|| s->avctx->p_masking
+ || s->avctx->border_masking
|| (s->flags&CODEC_FLAG_QP_RD))
&& !s->fixed_qscale;
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 71af4f4ec8..04f1e5bc80 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -501,6 +501,7 @@ static void adaptive_quantization(MpegEncContext *s, double q){
const float temp_cplx_masking= s->avctx->temporal_cplx_masking;
const float spatial_cplx_masking = s->avctx->spatial_cplx_masking;
const float p_masking = s->avctx->p_masking;
+ const float border_masking = s->avctx->border_masking;
float bits_sum= 0.0;
float cplx_sum= 0.0;
float cplx_tab[s->mb_num];
@@ -508,6 +509,8 @@ static void adaptive_quantization(MpegEncContext *s, double q){
const int qmin= s->avctx->lmin;
const int qmax= s->avctx->lmax;
Picture * const pic= &s->current_picture;
+ const int mb_width = s->mb_width;
+ const int mb_height = s->mb_height;
for(i=0; i<s->mb_num; i++){
const int mb_xy= s->mb_index2xy[i];
@@ -515,6 +518,10 @@ static void adaptive_quantization(MpegEncContext *s, double q){
float spat_cplx= sqrt(pic->mb_var[mb_xy]);
const int lumi= pic->mb_mean[mb_xy];
float bits, cplx, factor;
+ int mb_x = mb_xy % s->mb_stride;
+ int mb_y = mb_xy / s->mb_stride;
+ int mb_distance;
+ float mb_factor = 0.0;
#if 0
if(spat_cplx < q/3) spat_cplx= q/3; //FIXME finetune
if(temp_cplx < q/3) temp_cplx= q/3; //FIXME finetune
@@ -535,6 +542,23 @@ static void adaptive_quantization(MpegEncContext *s, double q){
factor*= (1.0 - (lumi-128)*(lumi-128)*lumi_masking);
else
factor*= (1.0 - (lumi-128)*(lumi-128)*dark_masking);
+
+ if(mb_x < mb_width/5){
+ mb_distance = mb_width/5 - mb_x;
+ mb_factor = (float)mb_distance / (float)(mb_width/5);
+ }else if(mb_x > 4*mb_width/5){
+ mb_distance = mb_x - 4*mb_width/5;
+ mb_factor = (float)mb_distance / (float)(mb_width/5);
+ }
+ if(mb_y < mb_height/5){
+ mb_distance = mb_height/5 - mb_y;
+ mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5));
+ }else if(mb_y > 4*mb_height/5){
+ mb_distance = mb_y - 4*mb_height/5;
+ mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5));
+ }
+
+ factor*= 1.0 - border_masking*mb_factor;
if(factor<0.00001) factor= 0.00001;