Skip to content

Commit afbd3cc

Browse files
committed
lavf/qsvvpp: Fix a transcoding issue when input isn't 64 bytes aligned
When the input is yuv420p format from software decoding, the vpp output may be incorrect when width is not 64 bytes aligned. see: ffmpeg -init_hw_device qsv=foo -filter_hw_device foo -i spam_720x480.avi -an -vcodec h264_qsv -vf [main]vpp_qsv=w=512:h=288[out] out.mp4 Patch is evolution from Gilles Vieira on #16, and root caused as: "When width = 720, after alignment the Y’s linesize is 736, and U, V’s line size is 384 and “736 != 384 * 2”. But mfxFrameSurface1 in current mSDK has only one linesize field for Y component; and I think it use half of Y’s linesize to be U, V’s linesize, and it’s the root cause of the issue." Idea-by: Gilles Vieira Signed-off-by: Zhong Li <zhong.li@intel.com>
1 parent be6cdf7 commit afbd3cc

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

libavfilter/qsvvpp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,12 @@ static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p
300300
qsv_frame->surface = (mfxFrameSurface1 *)qsv_frame->frame->data[3];
301301
} else {
302302
/* make a copy if the input is not padded as libmfx requires */
303-
if (picref->height & 31 || picref->linesize[0] & 31) {
303+
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(picref->format);
304+
if (picref->height & 31 || picref->linesize[0] & 31
305+
|| (!strcmp(desc->name, "yuv420p") && picref->linesize[0] & 63)) {
306+
int width_align = !strcmp(desc->name, "yuv420p") ? 64 : 32;
304307
qsv_frame->frame = ff_get_video_buffer(inlink,
305-
FFALIGN(inlink->w, 32),
308+
FFALIGN(inlink->w, width_align),
306309
FFALIGN(inlink->h, 32));
307310
if (!qsv_frame->frame)
308311
return NULL;

0 commit comments

Comments
 (0)