Fix #120077: Video output artifacts due to threaded YUV conversion

ffmpeg AVFrame objects should use correct alignment between image
rows, or otherwise bad things might happen. In this particular
case, multi-threaded libswscale RGB->YUV conversion was trampling
over 4 bytes of V plane, for each thread boundary.

Pull Request: https://projects.blender.org/blender/blender/pulls/120168
This commit is contained in:
Aras Pranckevicius
2024-04-02 13:03:05 +02:00
committed by Aras Pranckevicius
parent fd7e74aa23
commit 19ce05971d

View File

@@ -46,6 +46,7 @@ extern "C" {
# include <libavformat/avformat.h>
# include <libavutil/buffer.h>
# include <libavutil/channel_layout.h>
# include <libavutil/cpu.h>
# include <libavutil/imgutils.h>
# include <libavutil/opt.h>
# include <libavutil/rational.h>
@@ -256,14 +257,15 @@ static AVFrame *alloc_picture(AVPixelFormat pix_fmt, int width, int height)
}
/* allocate the actual picture buffer */
int size = av_image_get_buffer_size(pix_fmt, width, height, 1);
const size_t align = av_cpu_max_align();
int size = av_image_get_buffer_size(pix_fmt, width, height, align);
AVBufferRef *buf = av_buffer_alloc(size);
if (buf == nullptr) {
av_frame_free(&f);
return nullptr;
}
av_image_fill_arrays(f->data, f->linesize, buf->data, pix_fmt, width, height, 1);
av_image_fill_arrays(f->data, f->linesize, buf->data, pix_fmt, width, height, align);
f->buf[0] = buf;
f->format = pix_fmt;
f->width = width;