[FFmpeg-devel] [PATCH 2/2] avcodec/mpegvideo_enc: Remove custom plane copying code

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Apr 6 13:25:32 EEST 2024


It caused errors (see e.g. a066b8a809fa6d8b31398d41787822803f8762f2)
and would not support negative linesizes (this is currently
impossible to trigger as avcodec_default_get_buffer2() (used
internally by ff_encode_alloc_frame()) does not use negative
linesizes at all).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 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 a65ecc6839..f3e45c18d2 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -36,6 +36,7 @@
 #include <stdint.h>
 
 #include "libavutil/emms.h"
+#include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 #include "libavutil/intmath.h"
 #include "libavutil/mathematics.h"
@@ -1214,28 +1215,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 - src_stride + w);
-                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,
-- 
2.40.1



More information about the ffmpeg-devel mailing list