From f9243d34f19da816e05ad9e314e52b609e928bb1 Mon Sep 17 00:00:00 2001
From: Corey Hickey <bugfood-ml@fatooh.org>
Date: Sat, 3 Jun 2006 06:26:04 +0000
Subject: [PATCH] Make B-frame reduction sensitivity by b_strategy/vb_strategy
 = 1 user-tunable.

Originally committed as revision 5450 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavcodec/avcodec.h   | 7 +++++++
 libavcodec/mpegvideo.c | 2 +-
 libavcodec/utils.c     | 2 ++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d352edc97bd..eb0fe818569 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1977,6 +1977,13 @@ typedef struct AVCodecContext {
      * - decoding: unused
      */
     int mv0_threshold;
+
+    /**
+     * adjusts sensitivity of b_frame_strategy 1
+     * - encoding: set by user.
+     * - decoding: unused
+     */
+    int b_sensitivity;
 } AVCodecContext;
 
 /**
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index dac57c6cd0b..6393cc91fe9 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -2375,7 +2375,7 @@ static void select_input_picture(MpegEncContext *s){
                     }
                 }
                 for(i=0; i<s->max_b_frames+1; i++){
-                    if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/40) break;
+                    if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/s->avctx->b_sensitivity) break;
                 }
 
                 b_frames= FFMAX(0, i-1);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 84860e270be..ce664391171 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -741,6 +741,7 @@ static AVOption options[]={
 {"sc_factor", NULL, OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E},
 {"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E},
 {"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
+{"b_sensitivity", NULL, OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
 {NULL},
 };
 
@@ -796,6 +797,7 @@ void avcodec_get_context_defaults(AVCodecContext *s){
     s->nsse_weight= 8;
     s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE
     s->mv0_threshold= 256;
+    s->b_sensitivity= 40;
 
     s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
     s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
-- 
GitLab