From patchwork Mon Jan 27 03:53:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Middleton X-Patchwork-Id: 17577 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C3A9E44BD5E for ; Mon, 27 Jan 2020 06:00:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 48B5268A4AE; Mon, 27 Jan 2020 06:00:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f46.google.com (mail-io1-f46.google.com [209.85.166.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CC90868816C for ; Mon, 27 Jan 2020 06:00:32 +0200 (EET) Received: by mail-io1-f46.google.com with SMTP id d15so8465277iog.3 for ; Sun, 26 Jan 2020 20:00:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=g7KYzj/X01dHm0ZjWoXyxUNqZpJQfoST8DLk58RgtEM=; b=VIh7nZfX4nS5jpg5diP4V7+EB2iqDXUzSI1Ovh0NHmTVczm4jSb5mNNRmRcdt5ExSq 2ttsaRtWpRGGcCJGKaHX7nlhblwj2w09w64dm3cte5jOd0cMQzqDdYw/RN22xA3s2WEv D04hsbBjjNmql4fn3bdER/lG+ameOCWR0SgW+Lj5qYOtx7KGH4/ESacsk9B7ApX/ZOj2 pV/wk6TvF1kgMH6FNHSbtvuNm85J+ARKWWiM44dbizClwagPL2PF6Y6aafrLDAa6QpmD 3NVBUAe+oOPVkGfYcLIxih2ODKnGkgyOB1W26D6pKk/a9oEtqI/xUR9AG5fdmKCMFJ0r uBMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=g7KYzj/X01dHm0ZjWoXyxUNqZpJQfoST8DLk58RgtEM=; b=EMBQeEISvQdCjp7z3fkuh0Dq70Co1OGGwBhjMd+IvWMx3Wr+z2QVYRSKADZOU04uRc w0dznzfn7lGZwZvdzOlwbvy83K6dv3pEim6sSydsOcZ3kR4TTtxz9f9X9UdpoxXkwUgP NBmjGK94qZCWnsrthetDXXCQif+2jMiZIU7zhEZecKA9mtZt8gxZjqFrUv63dzS4J4/W l5vPDgMzwiaiOaAFp6C6ID4A1AKGem0YMjZNt4+6+9H8MVjOXuxjS2OCzIEv+8RAmcR1 29EjgSxjvqVIwJf9awrHrE7XCEMGNbynoFnrnPQSPHu45d6UgceDsPZseOFreBUZ6z6C FsbA== X-Gm-Message-State: APjAAAWUVdUydK5CcWsGO7X9MOL2YBpSZaTgs6VcrDq/NjTbks8K68Q6 V9HBjvYMR1hdhHlpgsp2Tvk/rIwTr/c= X-Google-Smtp-Source: APXvYqxOhRnL++DghFFUeltu1+qDQmomG0OjqOGxbphPL+2q4EdsXTHg48K8Z0y03/Kp/8yLshk1FA== X-Received: by 2002:a5d:9c12:: with SMTP id 18mr10799777ioe.211.1580097201845; Sun, 26 Jan 2020 19:53:21 -0800 (PST) Received: from debian (ip-173-121-26-41.englco.spcsdns.net. [173.121.26.41]) by smtp.gmail.com with ESMTPSA id a18sm3170978ioc.44.2020.01.26.19.53.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 19:53:20 -0800 (PST) Date: Sun, 26 Jan 2020 20:53:18 -0700 From: Ivan Middleton To: ffmpeg-devel@ffmpeg.org Message-ID: <20200127035318.qjbykxzoqgzsgsvl@debian> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180716 Subject: [FFmpeg-devel] [PATCH] avfilter/pad: round output width/height up instead of down. Fixes bugs #1618 and #8475. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The pad filter is currently broken for cases where all of the following hold: (1) chroma subsampling exists (very common), (2) an input dimension is odd (uncommon), and (3) the corresponding output dimension is either the same as the input, or an expression like "ow-iw" or "oh-ih" is used to place the image at the right/bottom edge and the extra padding is even in size. The cause of the breakage is essentially that the output width and height are being rounded downward, causing the image to exceed the padded area slightly. It seems best to me to simply round the output width/height up instead of down, so I've attached a patch to do that. This fixes bugs #1618 and #8475. Commands to reproduce the bug: # create 15x15 test jpeg with 4:2:0 subsampling ffmpeg -f lavfi -i color=red:15x15,format=rgb24 -vframes 1 -vf format=yuvj420p red.jpg # output size = input size. fails ffmpeg -i red.jpg -vf pad=iw:ih:0:0 pad1.png # input at bottom right of output. fails ffmpeg -i red.jpg -vf pad=iw+16:ih+16:ow-iw:oh-ih pad2.png Ivan From 52030219e09b5f9611ca6232b1f24197363fc23b Mon Sep 17 00:00:00 2001 From: Ivan Middleton Date: Sun, 26 Jan 2020 20:25:59 -0700 Subject: [PATCH] avfilter/pad: round output width/height up instead of down. Fixes bugs #1618 and #8475. --- libavfilter/vf_pad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index e86292e..493e342 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -178,8 +178,8 @@ static int config_input(AVFilterLink *inlink) if (s->y < 0 || s->y + inlink->h > s->h) s->y = var_values[VAR_Y] = (s->h - inlink->h) / 2; - s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w); - s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h); + s->w = ff_draw_round_to_sub(&s->draw, 0, +1, s->w); + s->h = ff_draw_round_to_sub(&s->draw, 1, +1, s->h); /* sanity check params */ if (s->w < inlink->w || s->h < inlink->h) { av_log(ctx, AV_LOG_ERROR, "Padded dimensions cannot be smaller than input dimensions.\n"); -- 2.20.1