From patchwork Fri Dec 22 10:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 45282 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp957637pzh; Fri, 22 Dec 2023 02:01:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcFOZ4nmFxaw8ohObte7aQmB42rc6mP2oSrMTQMoIUoYooYslk5eElgO4nWlCSy3SLS0vI X-Received: by 2002:a50:d744:0:b0:553:26db:ed73 with SMTP id i4-20020a50d744000000b0055326dbed73mr476975edj.72.1703239279622; Fri, 22 Dec 2023 02:01:19 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u23-20020a50c057000000b005540b2a32a5si1646277edd.129.2023.12.22.02.01.14; Fri, 22 Dec 2023 02:01:19 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b="IBI/mTM0"; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 23ED468D2B5; Fri, 22 Dec 2023 12:01:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02olkn2083.outbound.protection.outlook.com [40.92.50.83]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5017868D210 for ; Fri, 22 Dec 2023 12:01:04 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GLYlKoRX1MPn7dJ/ECvfsKXEyu/0sDLbM1NFykhNSvd5NccLRbzMjAmHtHkDoDSUZDmLXi9iKnYMAUqBvJfWJp8ZPdOf+eG13EieBqP2pqx7e9tPxgRQoY7VXPHDujMeKcTiRPPfTCzsnFNJKUkOnSGwRhFYGj4IE3gTSyp8VRKxSB3Q3D126dczh9UxjJ0KuH1ZRFoDVFMq8cawc93ANZzqsoUBrBoJLuQ7bBCyC0Wj8KSv/r8RzgerIE3WxAK5RpLH07Tr0Re4s7rvo4bniVOh8lqenhRBw1FcsxbYCErTDwtO+7kc5xrEX9J0tn7zWrhex/bU3JSbW9yMORXkng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=APE/FN3xuFfvQecAMtyK9uBz0TU6zZPRr8UCQl9CGd4=; b=UkuSga3I6FMOmJlZBeY/wh7WkKocw0tCVu/YZ1U/VpaJPLyfuU7DoJctpjuJBqF0q7Tr7RqDwQKUSTjhlxmq4KUMsRGtOhNpXoLF/xuTpRWNzkLNQ+wnIiwF+kI9AqPinoy1dL8SpNLs2/43bijw01QL8QJrD1GcSmc0uWOcMYDX6uqPy7WB2vCVfIEudJv+JZaT0OK38v86BpmMUbnO6R4syJUXhmMlvcqvl/qei0cisLCeFQKlmkd8UW/ojeTCVBDNoVAZVEWSeDYUPEueWWyVQf6euNZ5kQDLSJC8Fzx1FoaaLIQ5UDFu8XGuxkj8/9x1Hpjn4oYs0Sdb4ot6YA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=APE/FN3xuFfvQecAMtyK9uBz0TU6zZPRr8UCQl9CGd4=; b=IBI/mTM0tEpvKA6bGJHUcwZwhyv1iI7ZH3LQLGkuphEfNN1v8Fb0VL3NLheK2aqjCZn2YDUNIpOC0Tv4p9Yv0K6TtvpGuDsJc9fJd7NbZqA9tIYxpZIsdI6Ds5vezh0ztuqdW8R11HrX6kwSuVsfOpm+CV3lqBJn2EtlZt95B/1XNNnvOGBSmpPA7DG9BYTiB3VZimYwHB2ldOsKJ6yHdYJsPLxvNX+Tjyy/FCljxp5Q4UvIXKi+oL+ZMV4R08j4ZC4pKuwcLgcBS/KTsGMZZZEXawP097uTo1uZ7j3LjyUXigSmyubCvtwbtcYjJrMf+vYWhxrDar8oLutw/W8ecQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PR3P250MB0083.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:172::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.21; Fri, 22 Dec 2023 10:00:53 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::f59c:9cff:a42d:bde]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::f59c:9cff:a42d:bde%3]) with mapi id 15.20.7113.016; Fri, 22 Dec 2023 10:00:53 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 Dec 2023 11:02:20 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [zQVwkBb7aBd/LpgswB4J5zw6zNZobVNC81NHn2kVWaE=] X-ClientProxiedBy: FR0P281CA0234.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b2::18) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231222100220.2526071-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|PR3P250MB0083:EE_ X-MS-Office365-Filtering-Correlation-Id: d0366717-3f82-4eb9-d7a5-08dc02d4e26b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zd72OTwZZd3b7khxldOtyK374TxwwZo6SpCTIMVgvPHzh2qHLsbTTD/+MCMKKJ4PLvCu8Bg5RrlAPgqN/WA8EHHcvNHwAccWH+FYnukcEk+lB7RxTgPShlC5SPARtUVf8FxsCi9StRR/N2EoitB06zEtSJWxRsmEDievXoy/afmYKHHgUxHMpp5+hDqb3LAhMCZnala2tMkLhrYBihXDA0TfNdFCCZ7HDLFfHdiMA3WMFjiqVU9d+KnJ7QrMEYn3CrypE9ioM9RXq5NYiS22QllQQwcyAKeUtI3UQtTYtN5SNdL2XN7ieejHcNZsj7kMV8EpqFqYbgpeUHOf2txeSjpsLilUuwpF/59924a4pviYVxrR+9AQ6Y2Xfps99d2M0NUmsWFdTll/S89Y5lyuXwJv2XiOmlU3MZERUpmGfVjDIWwjWV6e7LpCYY2R/VQuQcQbgsHBKkcOm1GaqysAiStjboVcmH6oHZUuUicSmA72pix+EQ6eNUman0JivM4AuVRljZDcw/Lrbht+FvIQk0nKzxkQTobSF34PMxFQUL/P3kyoE3bBGGGAaBpxGfYsTO8ZNDOe2bCHYVqFbDrEsPST2YfzpJLbEzvEeJdaF8QtlI0cPpxwps0xz3EkMDRq X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jR5SJbnoxy7cbCZOMviYkK9HnXeeXZChB5i2fNEQ20eaiBB4izFWL+nwOa85Mwyt/S5Jps8O3GXA0lvP+GT1VkAY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1ZoBtb7gYiePsYSnlxRBvF/gELvF/e23qMXjwoyhvwn/W3conzqrGlMgKwbUkN6XbXfxbMxIFB0JbzUkOcE4viJ92I4EPOQkSRUtuMJcWgV7XMKF3f X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0366717-3f82-4eb9-d7a5-08dc02d4e26b X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2023 10:00:53.7599 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3P250MB0083 Subject: [FFmpeg-devel] [PATCH] avcodec/mpegvideo_enc: Don't copy non-existent padding X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vFLv+JPMLvfZ The allocated buffer of an AVFrame need not be height * linesize big. In case there is padding between lines, the last line need not have this padding. Pathological examples exist with height == 1 (where linesize is not really meaningful); non-pathological examples are produced by the separatefields filter, which simply offsets the pointers and doubles linesize, so that the frame created from the bottom field has only height - 1 lines with padding (containing the top field) and one line without padding. The mpegvideo encoders sometimes copy the input frames for padding/ alignment reasons and when doing so, there is a fast path in which everything is copied with one memcpy() of height * linesize. And this is wrong as explained above. Use av_image_copy_plane() instead of our ad-hoc code for copying. Fixes ticket #10754 (discovered by Zeng Yunxiang). (The above discussion presupposes linesize > 0 and would need some adaptation for negative linesizes; the code removed seems even more buggy for negative linesizes.) Signed-off-by: Andreas Rheinhardt --- 1. One could also use av_image_copy(). 2. The "direct" (non-copy) path only ensures a height mod 16, yet the non-direct mode sometimes pads to 32 (for non-progressive mpeg2). Seems fishy. libavcodec/mpegvideo_enc.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 6d2d417454..fac9bb7ae7 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -36,6 +36,7 @@ #include #include "libavutil/emms.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/intmath.h" #include "libavutil/mathematics.h" @@ -1201,28 +1202,16 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) int w = s->width >> h_shift; int h = s->height >> v_shift; const uint8_t *src = pic_arg->data[i]; - uint8_t *dst = pic->f->data[i]; + uint8_t *dst = pic->f->data[i] + !s->avctx->rc_buffer_size * INPLACE_OFFSET; int vpad = 16; + av_image_copy_plane(dst, dst_stride, src, src_stride, w, h); + if ( s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence && FFALIGN(s->height, 32) - s->height > 16) vpad = 32; - if (!s->avctx->rc_buffer_size) - dst += INPLACE_OFFSET; - - if (src_stride == dst_stride) - memcpy(dst, src, src_stride * h); - else { - int h2 = h; - uint8_t *dst2 = dst; - while (h2--) { - memcpy(dst2, src, w); - dst2 += dst_stride; - src += src_stride; - } - } if ((s->width & 15) || (s->height & (vpad-1))) { s->mpvencdsp.draw_edges(dst, dst_stride, w, h,