From c977039e585bfff28ecc037ef827c6c3d1ed88aa Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 16 Mar 2013 22:36:56 +0100 Subject: [PATCH 1/2] lavc, lavfi: fix counting number of planes in AVBufferRef wrappers Number of planes is not always equal to the number of components even for formats marked with PIX_FMT_PLANAR -- e.g. NV12 has three components in two planes. --- libavcodec/utils.c | 4 ++-- libavfilter/buffersrc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 4d57865629..e18f42d99a 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -660,11 +660,11 @@ do { \ if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); - if (!desc) { + planes = av_pix_fmt_count_planes(frame->format); + if (!desc || planes <= 0) { ret = AVERROR(EINVAL); goto fail; } - planes = (desc->flags & PIX_FMT_PLANAR) ? desc->nb_components : 1; for (i = 0; i < planes; i++) { int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0; diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 65cacf7d85..19419e6d25 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -186,11 +186,11 @@ do { \ if (ctx->outputs[0]->type == AVMEDIA_TYPE_VIDEO) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); - if (!desc) { + planes = av_pix_fmt_count_planes(frame->format); + if (!desc || planes <= 0) { ret = AVERROR(EINVAL); goto fail; } - planes = (desc->flags & PIX_FMT_PLANAR) ? desc->nb_components : 1; for (i = 0; i < planes; i++) { int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_w : 0; From 6599b087de62a5f9f2a8d61a1952d777d1bff804 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 18 Mar 2013 07:22:58 +0100 Subject: [PATCH 2/2] buffersrc: fix a typo. Vertical shift is log2_chroma_h, not log2_chroma_w. --- libavfilter/buffersrc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 19419e6d25..2219ba5f81 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -193,7 +193,7 @@ do { \ } for (i = 0; i < planes; i++) { - int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_w : 0; + int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0; int plane_size = (frame->height >> v_shift) * frame->linesize[i]; WRAP_PLANE(frame->buf[i], frame->data[i], plane_size);