ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | 
Sun Mar 16 10:30:48 2025 +0100| [1b537de8d4dc8d73f511d4ebe2520e2c70e2901f] | 
committer: Andreas Rheinhardt

avcodec/mpegvideo: Move noise_reduction to MPVMainEncContext

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1b537de8d4dc8d73f511d4ebe2520e2c70e2901f
---

 libavcodec/mpegvideo.h     |  2 --
 libavcodec/mpegvideo_enc.c | 19 +++++++++++--------
 libavcodec/mpegvideoenc.h  |  4 +++-
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 609052786e..69efc81096 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -473,8 +473,6 @@ typedef struct MpegEncContext {
 
     int error_rate;
 
-    int noise_reduction;
-
     int intra_penalty;
 } MpegEncContext;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 0c2ed2e931..b32b8fe768 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -442,7 +442,7 @@ static av_cold int init_buffers(MPVMainEncContext *const m, 
AVCodecContext *avct
     int has_b_frames = !!m->max_b_frames, nb_mv_tables = 1 + 5 * has_b_frames;
     int16_t (*mv_table)[2];
 
-    if (s->noise_reduction) {
+    if (m->noise_reduction) {
         if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_offset, 2))
             return AVERROR(ENOMEM);
         dct_error = av_mallocz(ALIGN - 1 + nb_slices * DCT_ERROR_SIZE);
@@ -1877,8 +1877,9 @@ static void frame_end(MPVMainEncContext *const m)
         s->last_non_b_pict_type = s->pict_type;
 }
 
-static void update_noise_reduction(MpegEncContext *s)
+static void update_noise_reduction(MPVMainEncContext *const m)
 {
+    MpegEncContext *const s = &m->s;
     int intra, i;
 
     for (intra = 0; intra < 2; intra++) {
@@ -1890,7 +1891,7 @@ static void update_noise_reduction(MpegEncContext *s)
         }
 
         for (i = 0; i < 64; i++) {
-            s->dct_offset[intra][i] = (s->noise_reduction *
+            s->dct_offset[intra][i] = (m->noise_reduction *
                                        s->dct_count[intra] +
                                        s->dct_error_sum[intra][i] / 2) /
                                       (s->dct_error_sum[intra][i] + 1);
@@ -1898,8 +1899,10 @@ static void update_noise_reduction(MpegEncContext *s)
     }
 }
 
-static void frame_start(MpegEncContext *s)
+static void frame_start(MPVMainEncContext *const m)
 {
+    MpegEncContext *const s = &m->s;
+
     s->cur_pic.ptr->f->pict_type = s->pict_type;
 
     if (s->pict_type != AV_PICTURE_TYPE_B) {
@@ -1907,9 +1910,9 @@ static void frame_start(MpegEncContext *s)
         ff_mpv_replace_picture(&s->next_pic, &s->cur_pic);
     }
 
+    av_assert2(!!m->noise_reduction == !!s->dct_error_sum);
     if (s->dct_error_sum) {
-        av_assert2(s->noise_reduction && s->encoding);
-        update_noise_reduction(s);
+        update_noise_reduction(m);
     }
 }
 
@@ -1959,7 +1962,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket 
*pkt,
 
         s->pict_type = s->new_pic->pict_type;
         //emms_c();
-        frame_start(s);
+        frame_start(m);
 vbv_retry:
         ret = encode_picture(m, pkt);
         if (growing_buffer) {
@@ -3598,7 +3601,7 @@ static void merge_context_after_encode(MpegEncContext 
*dst, MpegEncContext *src)
     MERGE(encoding_error[1]);
     MERGE(encoding_error[2]);
 
-    if (dst->noise_reduction){
+    if (dst->dct_error_sum) {
         for(i=0; i<64; i++){
             MERGE(dct_error_sum[0][i]);
             MERGE(dct_error_sum[1][i]);
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 12a1804428..ca76091feb 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -68,6 +68,8 @@ typedef struct MPVMainEncContext {
 
     int scenechange_threshold;
 
+    int noise_reduction;
+
     float border_masking;
     int lmin, lmax;
     int vbv_ignore_qmax;
@@ -199,7 +201,7 @@ FF_MPV_OPT_CMP_FUNC, \
 {"skip_factor", "Frame skip factor",                                
FF_MPV_MAIN_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_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, .unit = "cmp_func" }, \
-{"noise_reduction", "Noise reduction",                              
FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, 
FF_MPV_OPT_FLAGS }, \
+{"noise_reduction", "Noise reduction",                              
FF_MPV_MAIN_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 }, \
 
 #define FF_MPV_COMMON_BFRAME_OPTS \

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to