From patchwork Sun Aug 27 19:51:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 43361 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7194:b0:149:dfde:5c0a with SMTP id s20csp974601pzb; Sun, 27 Aug 2023 12:51:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEamAh1eDeg1rwB0n47PKsaMTd86Ix0KHISEkmV/XQhkeF5hMa9kLZowkhkTBExtnVOdqro X-Received: by 2002:a05:6402:558:b0:523:cfa4:5c3d with SMTP id i24-20020a056402055800b00523cfa45c3dmr11246853edx.13.1693165890126; Sun, 27 Aug 2023 12:51:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693165890; cv=none; d=google.com; s=arc-20160816; b=YajGbjQdZYHuzij7Kf/SLyfX/WpfnGr3ySD/AVN75cSs99K9wjumOyiiISupk/KAaO iumN+t0YIaIjqSHl4sttNvU3PVHZRDZViAv+2CaEE+SR6ZHyRmG18CLFNTh6BSQjSbT8 sMWxxI8RbwkqTkytKTlX8j/lf1QG/bJ04PgU/OzRgpUjlIsFD4YZoq6PoZWa64Thfi4i jBWlpncQdSa0nedbyD/z/obcCft2HWQXLFrJoAIqoaEHFnxn3NTLZSQoltafkZrvwpg9 B+/ojhNy6I8/SmZIVlA53EnyPR7CWyq0bh+JHPbW7wLLqVnJeaT4ci1plzFdSBucvAIv IwOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=KcqZ3rorluEcYZK0T9MbBYqPXGwhCGbLBXHOVjfU4D8=; fh=+bdjGe20eEUjtjncwA1dnEEVYNfJL4vyhV+sIRR4l+g=; b=UxG1tKb6m/hbidqyIaK7G7ytR4bpkHxhUKS5MdaJfswwgj51tMMo8aktMGUjbUC/nS BACkF/ir6vPjpkXlONBEOI15LGUbkCAcFwMPKNRm7Diw6Uaz26xw6emyK00ia0fi46jg vZPpwenXnBMA2bH2+e40Z4v27V/j53KsEcrRmHLl4Rq404U3Qn68At6D5ar9ufa/3BUs pckhYMAQ9ELSpj80t4RYID6alkVcK1w/8DlG6nJdcXgRyrKE60d+5ErphZ7bSRKK6ItQ 5umNsLJuKQhVHcRp78STlXGv83EzV8nWvfFpJNuGJsScWjJMpAKE6/EjfOUfACHjYNsf FZUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=HnC6Tpeq; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z6-20020aa7cf86000000b005237a872472si1617812edx.37.2023.08.27.12.51.29; Sun, 27 Aug 2023 12:51:30 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=HnC6Tpeq; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7914C68C5CE; Sun, 27 Aug 2023 22:51:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4C5DA68C21A for ; Sun, 27 Aug 2023 22:51:19 +0300 (EEST) Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6bf106fb6a0so248940a34.0 for ; Sun, 27 Aug 2023 12:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693165877; x=1693770677; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RAz1oM6I7KYkUyz/8vRDmnlfU4woWKi5aZuNwbgaz/M=; b=HnC6TpeqwJfKZRJOSg8LUuuL+Gn2biOeGK8EsdWtrqhBvWLKC9pRq9H51TVJ8iMrVd NUbkWN2R+qKHi+eMOGtHpVxReFnBLGHw6RV+wb6vrsdqzpMY+JqbITFTNC6JPfqHx7xw bqdEWqa6rDn8rbwrxPOLU7DQJ9CJvdAe4NlfxjPXstQXc72iiBtgrQfkZ3mEwr7mYgt1 nuRZv9nKY/2o5/N23x0dEI9iD0CVXUR8TLaiVgYwTSYExsRLvo9D3xkL0ClO44R5wi1j fXj5kNiPcqhWm3/0gpnkLfo5/ZyurV14IEo5dReMTQocyyasDyv0BYOqXvvJ8FP7TQnS eikQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693165877; x=1693770677; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RAz1oM6I7KYkUyz/8vRDmnlfU4woWKi5aZuNwbgaz/M=; b=mFLdjaV2MZfjcNGC6+1K4c5SGoJ/l/L1EbgRhk7wE5CzgIBdxKs21sPAu6YkXBZlCz Usd/wqblbBD+3Ff2BIvwR2G1Lay1OkVg4LOaAxHiF8WjWm+uVKorNhL8zIhJ2RtTQLQz rbkQYI5tWDVTa0GpVwGpSHXlOAm8mPWxVD6LeQz5Q9z5C8i8SP2GCCnVqCSWAN1bM5hH z5CxYi5DPA1oGxa9DKXCWUCd+7wd9pBkVTw/2uFW5PiJDiCEzyTw/VOzoghbiQq4pXt+ a5dSGGeZXNQQ6zPVp/eBUvzXnyuFGNB98+76Wj0pN8jlVJlwk+CJdNs/vqmgEFjULhH5 PWvw== X-Gm-Message-State: AOJu0YwY2dsyksRcrdvoq+m1/LRHt65Pr65tZ7QiIgbE7lu/iTys+zHq 56PFr5Tv6U8yLWZ4grHMovdmuh6M+A0= X-Received: by 2002:a05:6870:6124:b0:1b7:5e47:5b75 with SMTP id s36-20020a056870612400b001b75e475b75mr26297520oae.4.1693165877602; Sun, 27 Aug 2023 12:51:17 -0700 (PDT) Received: from gauss.local (c-68-56-149-176.hsd1.mi.comcast.net. [68.56.149.176]) by smtp.gmail.com with ESMTPSA id n191-20020a0dcbc8000000b0056d51c39c1fsm1733983ywd.23.2023.08.27.12.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 12:51:17 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Sun, 27 Aug 2023 15:51:15 -0400 Message-ID: <20230827195115.105591-1-leo.izen@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_pad: respect frame colorspace tag in RGB to YUV conversion X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Leo Izen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: X3S0g1Mfyuup vf_pad calls ff_draw_init, which assumes BT.709 and TV range for its YUV matricies. Since the filter only accepts RGB inputs for the color argument, it needs to convert them to YUV for YUV input video, and it should respect the tagged colormatrix when doing such a conversion, but it does not. It can do this by calling ff_draw_init2, and this patch causes the filter to re-init when the first frame is received, as that is when that colormatrix tag becomes available. If the filter is not initialized before the first frame, then an assertion will fail in avfilter.c when it does sanity checks on input/output dimensions, so the original initialization cannot be skipped. Signed-off-by: Leo Izen --- libavfilter/vf_pad.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index e52f7284d4..01de896772 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -100,9 +100,10 @@ typedef struct PadContext { FFDrawColor color; int eval_mode; ///< expression evaluation mode + int configured_input; ///< if config_input has been called yet } PadContext; -static int config_input(AVFilterLink *inlink) +static int config_frame_input(AVFilterLink *inlink, const AVFrame *frame) { AVFilterContext *ctx = inlink->dst; PadContext *s = ctx->priv; @@ -111,7 +112,10 @@ static int config_input(AVFilterLink *inlink) double var_values[VARS_NB], res; char *expr; - ff_draw_init(&s->draw, inlink->format, 0); + if (frame) + ff_draw_init2(&s->draw, inlink->format, frame->colorspace, frame->color_range, 0); + else + ff_draw_init(&s->draw, inlink->format, 0); ff_draw_color(&s->draw, &s->color, s->rgba_color); var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; @@ -216,6 +220,11 @@ eval_fail: } +static int config_input(AVFilterLink *inlink) +{ + return config_frame_input(inlink, NULL); +} + static int config_output(AVFilterLink *outlink) { PadContext *s = outlink->src->priv; @@ -326,11 +335,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFilterLink *outlink = inlink->dst->outputs[0]; AVFrame *out; int needs_copy; - if(s->eval_mode == EVAL_MODE_FRAME && ( + if((s->eval_mode == EVAL_MODE_FRAME && ( in->width != s->inlink_w || in->height != s->inlink_h || in->format != outlink->format - || in->sample_aspect_ratio.den != outlink->sample_aspect_ratio.den || in->sample_aspect_ratio.num != outlink->sample_aspect_ratio.num)) { + || in->sample_aspect_ratio.den != outlink->sample_aspect_ratio.den || in->sample_aspect_ratio.num != outlink->sample_aspect_ratio.num)) || !s->configured_input) { int ret; inlink->dst->inputs[0]->format = in->format; @@ -341,7 +350,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) inlink->dst->inputs[0]->sample_aspect_ratio.num = in->sample_aspect_ratio.num; - if ((ret = config_input(inlink)) < 0) { + if ((ret = config_frame_input(inlink, in)) < 0) { s->inlink_w = -1; return ret; } @@ -349,6 +358,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) s->inlink_w = -1; return ret; } + + s->configured_input = 1; } needs_copy = frame_needs_copy(s, in);