[FFmpeg-devel] [PATCH 41/41] avcodec/mpegvideo: Move frame_skip_(exp|cmp) to MPVMainEncContext

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sun Jan 30 08:27:49 EET 2022


Only used by the main encoding thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
frame_skip_factor/threshold are used by slice threads;
they (and several other fields) could be moved by adding
a pointer to the const MPVMainContext. I intend to do this
in the future.

 libavcodec/mpegvideo.h     | 2 --
 libavcodec/mpegvideo_enc.c | 8 ++++----
 libavcodec/mpegvideoenc.h  | 7 +++++--
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index bf71d6242b..fc271991fd 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -479,8 +479,6 @@ typedef struct MPVContext {
     /* frame skip options for encoding */
     int frame_skip_threshold;
     int frame_skip_factor;
-    int frame_skip_exp;
-    int frame_skip_cmp;
 
     int noise_reduction;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1a88e4fb93..8c369a94ec 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -892,7 +892,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
     s->quant_precision = 5;
 
     ff_set_cmp(&s->mecc, s->mecc.ildct_cmp,      avctx->ildct_cmp);
-    ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp);
+    ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, m->frame_skip_cmp);
 
     if (CONFIG_H261_ENCODER && s->out_format == FMT_H261) {
         ff_h261_encode_init(m);
@@ -1234,7 +1234,7 @@ static int skip_check(MPVMainEncContext *m, Picture *p, Picture *ref)
                 uint8_t *rptr = ref->f->data[plane] + 8 * (x + y * stride);
                 int v = s->mecc.frame_skip_cmp[1](s, dptr, rptr, stride, 8);
 
-                switch (FFABS(s->frame_skip_exp)) {
+                switch (FFABS(m->frame_skip_exp)) {
                 case 0: score    =  FFMAX(score, v);          break;
                 case 1: score   += FFABS(v);                  break;
                 case 2: score64 += v * (int64_t)v;                       break;
@@ -1248,9 +1248,9 @@ static int skip_check(MPVMainEncContext *m, Picture *p, Picture *ref)
 
     if (score)
         score64 = score;
-    if (s->frame_skip_exp < 0)
+    if (m->frame_skip_exp < 0)
         score64 = pow(score64 / (double)(s->mb_width * s->mb_height),
-                      -1.0/s->frame_skip_exp);
+                      -1.0/m->frame_skip_exp);
 
     if (score64 < s->frame_skip_threshold)
         return 1;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index ad55448363..f18463c2bb 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -87,6 +87,9 @@ typedef struct MPVMainEncContext {
     /* temp buffers for rate control */
     float *cplx_tab, *bits_tab;
 
+    int frame_skip_exp;
+    int frame_skip_cmp;
+
     /* temporary frames used by b_frame_strategy == 2 */
     AVFrame *tmp_frames[MAX_B_FRAMES + 2];
     int b_frame_strategy;
@@ -181,8 +184,8 @@ FF_MPV_OPT_CMP_FUNC, \
 { "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \
 {"skip_threshold", "Frame skip threshold",                          FF_MPV_OFFSET(frame_skip_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"skip_factor", "Frame skip factor",                                FF_MPV_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
-{"skip_exp", "Frame skip exponent",                                 FF_MPV_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
-{"skip_cmp", "Frame skip compare function",                         FF_MPV_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
+{"skip_exp", "Frame skip exponent",                                 FF_MPV_MAIN_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
+{"skip_cmp", "Frame skip compare function",                         FF_MPV_MAIN_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 {"sc_threshold", "Scene change threshold",                          FF_MPV_MAIN_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"noise_reduction", "Noise reduction",                              FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"ps", "RTP payload size in bytes",                             FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
-- 
2.32.0



More information about the ffmpeg-devel mailing list