[FFmpeg-devel] [PATCH] avutil/imgutils: optimize image copy efficiency

xufuji456 839789740 at qq.com
Thu May 4 10:54:35 EEST 2023


It makes sense when copying 4K/8K video, if linesize
equals to aligned linesize.

Signed-off-by: xufuji456 <839789740 at qq.com>
---
 libavutil/imgutils.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 9ab5757cf6..1d432e7a57 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -525,10 +525,17 @@ int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
         const uint8_t *src = src_data[i];
         h = (height + (1 << shift) - 1) >> shift;
 
-        for (j = 0; j < h; j++) {
-            memcpy(dst, src, linesize[i]);
-            dst += FFALIGN(linesize[i], align);
-            src += src_linesize[i];
+        if (FFALIGN(linesize[i], align) == linesize[i] && src_linesize[i] == linesize[i]) {
+            int size = linesize[i] * h;
+            memcpy(dst, src, size);
+            dst += size;
+            src += size;
+        } else {
+            for (j = 0; j < h; j++) {
+                memcpy(dst, src, linesize[i]);
+                dst += FFALIGN(linesize[i], align);
+                src += src_linesize[i];
+            }
         }
     }
 
-- 
2.32.0 (Apple Git-132)



More information about the ffmpeg-devel mailing list