[FFmpeg-cvslog] avcodec/motion_est: Reset scene_change score, MB variance stats
Andreas Rheinhardt
git at videolan.org
Wed Mar 26 06:10:59 EET 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Wed Mar 19 15:18:17 2025 +0100| [854a3ed54734719deddce7e2f18413c874b498e3] | committer: Andreas Rheinhardt
avcodec/motion_est: Reset scene_change score, MB variance stats
Reset them in ff_me_init_pic(). It is the appropriate place for it
and allows to remove resetting code from multiple places
(e.g. mpegvideo_enc.c resetted it in two different places
(one for the main slice context, one for all the others)).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=854a3ed54734719deddce7e2f18413c874b498e3
---
libavcodec/motion_est.c | 4 ++++
libavcodec/mpegvideo_enc.c | 12 +++---------
libavcodec/snowenc.c | 1 -
3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index fc2ca993bc..fd3cf04cd8 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -397,6 +397,10 @@ void ff_me_init_pic(MPVEncContext *const s)
c->hpel_put[2][0]= c->hpel_put[2][1]=
c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel;
}
+ /* Reset the average MB variance and scene change stats */
+ c->scene_change_score = 0;
+ c->mb_var_sum_temp =
+ c->mc_mb_var_sum_temp = 0;
}
#define CHECK_SAD_HALF_MV(suffix, x, y) \
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index f507fa5788..5ef0900ec0 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3586,9 +3586,9 @@ static int encode_thread(AVCodecContext *c, void *arg){
#define MERGE(field) dst->field += src->field; src->field=0
static void merge_context_after_me(MPVEncContext *const dst, MPVEncContext *const src)
{
- MERGE(me.scene_change_score);
- MERGE(me.mc_mb_var_sum_temp);
- MERGE(me.mb_var_sum_temp);
+ ADD(me.scene_change_score);
+ ADD(me.mc_mb_var_sum_temp);
+ ADD(me.mb_var_sum_temp);
}
static void merge_context_after_encode(MPVEncContext *const dst, MPVEncContext *const src)
@@ -3680,10 +3680,6 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
int bits;
int context_count = s->c.slice_context_count;
- /* Reset the average MB variance */
- s->me.mb_var_sum_temp =
- s->me.mc_mb_var_sum_temp = 0;
-
/* we need to initialize some time vars before we can encode B-frames */
// RAL: Condition added for MPEG1VIDEO
if (s->c.out_format == FMT_MPEG1 || (s->c.h263_pred && s->c.msmpeg4_version == MSMP4_UNUSED))
@@ -3691,8 +3687,6 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
if (CONFIG_MPEG4_ENCODER && s->c.codec_id == AV_CODEC_ID_MPEG4)
ff_set_mpeg4_time(s);
- s->me.scene_change_score=0;
-
// s->lambda = s->c.cur_pic.ptr->quality; //FIXME qscale / ... stuff for ME rate distortion
if (s->c.pict_type == AV_PICTURE_TYPE_I) {
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 5b78b0edbf..a15960e4a3 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -1867,7 +1867,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
mpv->c.f_code = 1;
mpv->c.pict_type = pic->pict_type;
mpv->me.motion_est = enc->motion_est;
- mpv->me.scene_change_score = 0;
mpv->me.dia_size = avctx->dia_size;
mpv->c.quarter_sample = (s->avctx->flags & AV_CODEC_FLAG_QPEL)!=0;
mpv->c.out_format = FMT_H263;
More information about the ffmpeg-cvslog
mailing list