Commit ec28d970eb for ffmpeg
commit ec28d970eb5ad6abbdd53a461e2548ee0762d5d7
Author: Zhao Zhili <quinkblack@foxmail.com>
Date: Wed Dec 2 13:17:48 2026 +0800
avcodec/videotoolboxenc: copy packed frames through the buffer address
CoreVideo documents the per-plane address and stride accessors as
returning nothing for a buffer that is not planar. Packed input such as
BGRA was copied through them, which relies on behavior the
documentation does not promise.
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 5a8552a5a9..37324866d3 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -2424,9 +2424,14 @@ static int copy_avframe_to_pixel_buffer(AVCodecContext *avctx,
int dst_stride[4] = {0};
uint8_t *dst_addr[4] = {0};
- for (int i = 0; i < num_planes; i++) {
- dst_addr[i] = (uint8_t*)CVPixelBufferGetBaseAddressOfPlane(cv_img, i);
- dst_stride[i] = CVPixelBufferGetBytesPerRowOfPlane(cv_img, i);
+ if (CVPixelBufferIsPlanar(cv_img)) {
+ for (int i = 0; i < num_planes; i++) {
+ dst_addr[i] = (uint8_t*)CVPixelBufferGetBaseAddressOfPlane(cv_img, i);
+ dst_stride[i] = CVPixelBufferGetBytesPerRowOfPlane(cv_img, i);
+ }
+ } else {
+ dst_addr[0] = (uint8_t*)CVPixelBufferGetBaseAddress(cv_img);
+ dst_stride[0] = CVPixelBufferGetBytesPerRow(cv_img);
}
av_image_copy2(dst_addr, dst_stride, frame->data, frame->linesize,
frame->format, frame->width, frame->height);