From 326dff7d054f260b11f51062c2d7fc9a537ff58c Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 6 Apr 2011 23:06:47 +0200 Subject: [PATCH] Fix ticket34 Signed-off-by: Michael Niedermayer --- libavcodec/mpeg4videoenc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index 2af898b955..d6834a6e40 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -650,8 +650,6 @@ void mpeg4_encode_mb(MpegEncContext * s, x= s->mb_x*16; y= s->mb_y*16; - if(x+16 > s->width) x= s->width-16; - if(y+16 > s->height) y= s->height-16; offset= x + y*s->linesize; p_pic= s->new_picture.data[0] + offset; @@ -667,7 +665,21 @@ void mpeg4_encode_mb(MpegEncContext * s, b_pic= pic->data[0] + offset; if(pic->type != FF_BUFFER_TYPE_SHARED) b_pic+= INPLACE_OFFSET; - diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16); + + if(x+16 > s->width || y+16 > s->height){ + int x1,y1; + int xe= FFMIN(16, s->width - x); + int ye= FFMIN(16, s->height- y); + diff=0; + for(y1=0; y1linesize] - b_pic[x1+y1*s->linesize]); + } + } + diff= diff*256/(xe*ye); + }else{ + diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16); + } if(diff>s->qscale*70){ //FIXME check that 70 is optimal s->mb_skipped=0; break;