This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch release/9.1
in repository ffmpeg.

commit 9a35b523152e3794179befe4fe0110712ef95519
Author:     Baptiste Coudurier <[email protected]>
AuthorDate: Sun Nov 15 11:08:12 2026 -0800
Commit:     Michael Niedermayer <[email protected]>
CommitDate: Thu Nov 19 14:56:30 2026 +0100

    avcodec/libx264: apply ROI offsets per macroblock pair when interlaced
    
    A field coded pair spreads both map rows over its lines, so set both rows
    of each pair a region touches; also size the map for x264's even row count.
    
    ROI map overread reported by Forgejo_Fairy in review of #25875; allocation
    fix by lusoris in #25909.
    
    Signed-off-by: Baptiste Coudurier <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    (cherry picked from commit 166b5d69ad67eb6e34ef3591ff8967d69e05ab09)
    Signed-off-by: Michael Niedermayer <[email protected]>
---
 libavcodec/libx264.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index e5a853c10a..f83be47e0c 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -410,6 +410,10 @@ static int setup_roi(AVCodecContext *ctx, x264_picture_t 
*pic,
 
     int mbx = (frame->width + MB_SIZE - 1) / MB_SIZE;
     int mby = (frame->height + MB_SIZE - 1) / MB_SIZE;
+    /* x264 rounds the macroblock row count up to an even number for
+     * interlaced and fake-interlaced encoding and reads quant_offsets
+     * over that grid, so size the map for it. */
+    int mby_alloc = FFALIGN(mby, 2);
     int qp_range = 51 + 6 * (x4->params.i_bitdepth - 8);
     int nb_rois;
     const AVRegionOfInterest *roi;
@@ -438,7 +442,7 @@ static int setup_roi(AVCodecContext *ctx, x264_picture_t 
*pic,
     }
     nb_rois = size / roi_size;
 
-    qoffsets = av_calloc(mbx * mby, sizeof(*qoffsets));
+    qoffsets = av_calloc(mbx * mby_alloc, sizeof(*qoffsets));
     if (!qoffsets)
         return AVERROR(ENOMEM);
 
@@ -452,6 +456,14 @@ static int setup_roi(AVCodecContext *ctx, x264_picture_t 
*pic,
 
         starty = FFMIN(mby, roi->top / MB_SIZE);
         endy   = FFMIN(mby, (roi->bottom + MB_SIZE - 1)/ MB_SIZE);
+        if (x4->params.b_interlaced && starty < endy) {
+            /* A macroblock pair may be field coded, in which case each of
+             * its two rows covers every other line of the pair's 32 lines.
+             * Apply the offset to both rows of each pair the region
+             * touches. */
+            starty &= ~1;
+            endy    = FFALIGN(endy, 2);
+        }
         startx = FFMIN(mbx, roi->left / MB_SIZE);
         endx   = FFMIN(mbx, (roi->right + MB_SIZE - 1)/ MB_SIZE);
 

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to