From patchwork Mon May 20 01:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Scholz X-Patchwork-Id: 49378 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:5c1:0:b0:460:55fa:d5ed with SMTP id 184csp6618vqf; Wed, 29 May 2024 18:21:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV+wEJRjBdVsncyi1KN572L40UtzOBYxmDBQ1DMm68VOsGTJyM2WHE94l9bjV7JEjwHgv8LqY4ZDX9Xv+uaoFXM/9XjxhwbP8JeNQ== X-Google-Smtp-Source: AGHT+IGV06kcsE+/uXqTAtQ+1scKMWmMyI8y2Nb3KiDadTqzfPJ72tiQikC8IG0GeKWw6W3FCEry X-Received: by 2002:a05:6512:3453:b0:528:16d7:b6c7 with SMTP id 2adb3069b0e04-52b7d4905famr589394e87.58.1717032082865; Wed, 29 May 2024 18:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717032082; cv=none; d=google.com; s=arc-20160816; b=x+wFZTZHKWT3Nt6xiNSX7AJ5V0GUl2hzAMDlpYukEs65qAEfKJHiBFqtZQEnp9xk1b yYscnHEclHfIk1EVsIvFsdqEIoRR/WzzZLIG88l2XXZBtlIGbc7Ccz2jzT++v7UmZUUT TnkTdX3KRD/Vr1GvH/OgI+B2HGxZtGowBqyQ7sN842FbH4nI4Ve0zwh24bPaqLODCKSB 5o9c1ERm4gooBViZ2Rl3+e+DzU8UqVz3j6uazGRohfZOoaezGyrTVyQKCk6dyTqpTdmq aMgXuqclFjjZU2NWHXAZfWuCiNlkAwYjZoMpWEABJX3TaI7u9lDzliXwgvr9Nxe7YQc6 aq3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:date:from:to:message-id:dkim-signature :delivered-to; bh=/WK761eroo+AWntSPFeR1oLIuHJcCUrwrjDSmYUMgXo=; fh=5IeVwzS1vbVKjIV8MP3mnmnRtZGb8uteQ9r4QD2keV0=; b=N5XpDEyKNn8KJKmOLx0Axm5ZErMG0WqR1N/3JhzZAkvZBJ/8e7y7NO+TDXHnU6qkIJ 4CnmY04P9RsLPiOGvAWxSM3fydoLbqwqOxoVVBuB7LpjSEF5xZLQwib1T2NhBLjLwNgH eW9BPm8VxrZGi6MgR5DGRULybQukDwtRIgNn2+UmdTJMtdN0RZjpTaA6E2N5Pj9+Bk8u F7yLWFhw5wHzXN8ZZlEr61hoUXm/P5imJkVwqkZZS6SxtOIW6XCK+gh/smzKrv6JB7/r PqF9QO36e0ilX3VgfHv4dUXWiZvuf2xfFPBttX+LKXMI7YEq86/e0aR9MaHChi0eWrvL 1edA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=FoKaql97; 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 2adb3069b0e04-529a52e638esi3349522e87.513.2024.05.29.18.21.22; Wed, 29 May 2024 18:21:22 -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=20230601 header.b=FoKaql97; 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 B885668D4BA; Thu, 30 May 2024 04:21:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D55B368D0AD for ; Thu, 30 May 2024 04:21:11 +0300 (EEST) Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2ea84766ad7so3259951fa.1 for ; Wed, 29 May 2024 18:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717032071; x=1717636871; darn=ffmpeg.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=EmhOjAr9Q3BzY/VT/YcPPL/1CMotpu1kXelC1Kh7mOc=; b=FoKaql97XR0kTMIHFTteQOX+rb3fzMsH4TFRV7Xb0FJmyNOOKsM++slNVzdiwxbemj 2Nlx53e0tmgSTdafdptWWygu5BIbv3t6+Cqh9cmjKqpBO+sFJeN+mT1VM/fStqkJspjB sJ2oyIzIVXYkrzn1qUqlKOsw9WP0j2mEzSkWygBBmx1LPa41clK5rGjSD3t9/KMDJZVx InXSB0dwWHFufdz+HRF60J2DddCdBfjZiYuNXHUEB2iAbEWQmB9MkT5TPR5PC6ZJP5UD xYaR4MQiiCd/dzrLaIMOjtt8JX1FHT6O66ejT5gkmZ9loyEC/a3gsEmNihp2hODraro4 jouw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717032071; x=1717636871; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EmhOjAr9Q3BzY/VT/YcPPL/1CMotpu1kXelC1Kh7mOc=; b=HXaK9Xe+mPVFWnohK7xdtrAvQ4y/Tq/q6bF6XpFGirQwIhA9hHqf0cn7/igHHLnIjz Zv9mddykzlnnwQ892gR0j2zf//FhTTHUoQ7ycfNdJrCH82P38clz4kIgCX3E4MvKnp9p B47GW7JMgeEpd9oZFWsBg0YGwG6a4v31l95XTXd9m76RnoqFUNpm3uUIVpBWykK8/VFu x0qBH5auVj6hVFZeovNx7xSZSM75WgEePg3IRHZuuwwIP6jvpCU0zxb9LoAFA4riS5xd 4sU1aTuAeBVWR/dzvJsWcAGnechF41eaiyDXE2Ck//IA+HbAPWFDsJHdhWktIXjLV8jE KhaQ== X-Gm-Message-State: AOJu0Ywu2Galeg8zBVekWnt7FNK8jjQWSvyeIohhEllMXuzV2i9NCH12 gf699qLR7r2eLGlh5PGX/pqfsOcwrhWKbZTAVRb8i724Jqvp4x1efE6JZA== X-Received: by 2002:a2e:bb83:0:b0:2ea:8440:c3f0 with SMTP id 38308e7fff4ca-2ea8485478dmr4640621fa.36.1717032070793; Wed, 29 May 2024 18:21:10 -0700 (PDT) Received: from localhost (p200300cccf0f49001441a6a3c951ef29.dip0.t-ipconnect.de. [2003:cc:cf0f:4900:1441:a6a3:c951:ef29]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-578523cba01sm9160400a12.35.2024.05.29.18.21.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 May 2024 18:21:09 -0700 (PDT) Message-Id: To: From: "Marvin Scholz" Date: Mon, 20 May 2024 03:12:01 +0200 Subject: [FFmpeg-devel] [PATCH v3 1/3] avutil/hwcontext_videotoolbox: Unset undefined values 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: l7WMS8ra02rN When mapping AVFrame properties to the CVBuffer attachments, it is necessary to properly delete undefined attachments, else we can leave incorrect values in there guessed from VideoToolbox for example, leading to inconsistent results where the AVFrame and CVBuffer differ in metadata. Ref #10884 --- libavutil/hwcontext_videotoolbox.c | 76 ++++++++++++++++-------------- 1 file changed, 41 insertions(+), 35 deletions(-) base-commit: fa3b153cb1eba0d68327c716842c9a38f95c1667 diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c index 9f82b104c3..0af2ab822f 100644 --- a/libavutil/hwcontext_videotoolbox.c +++ b/libavutil/hwcontext_videotoolbox.c @@ -342,8 +342,10 @@ static int vt_pixbuf_set_par(void *log_ctx, CFNumberRef num = NULL, den = NULL; AVRational avpar = src->sample_aspect_ratio; - if (avpar.num == 0) + if (avpar.num == 0) { + CVBufferRemoveAttachment(pixbuf, kCVImageBufferPixelAspectRatioKey); return 0; + } av_reduce(&avpar.num, &avpar.den, avpar.num, avpar.den, @@ -423,7 +425,10 @@ static int vt_pixbuf_set_chromaloc(void *log_ctx, kCVImageBufferChromaLocationTopFieldKey, loc, kCVAttachmentMode_ShouldPropagate); - } + } else + CVBufferRemoveAttachment( + pixbuf, + kCVImageBufferChromaLocationTopFieldKey); return 0; } @@ -534,52 +539,53 @@ static int vt_pixbuf_set_colorspace(void *log_ctx, Float32 gamma = 0; colormatrix = av_map_videotoolbox_color_matrix_from_av(src->colorspace); - if (!colormatrix && src->colorspace != AVCOL_SPC_UNSPECIFIED) - av_log(log_ctx, AV_LOG_WARNING, "Color space %s is not supported.\n", av_color_space_name(src->colorspace)); + if (colormatrix) + CVBufferSetAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey, + colormatrix, kCVAttachmentMode_ShouldPropagate); + else { + CVBufferRemoveAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey); + if (src->colorspace != AVCOL_SPC_UNSPECIFIED) + av_log(log_ctx, AV_LOG_WARNING, + "Color space %s is not supported.\n", + av_color_space_name(src->colorspace)); + } colorpri = av_map_videotoolbox_color_primaries_from_av(src->color_primaries); - if (!colorpri && src->color_primaries != AVCOL_PRI_UNSPECIFIED) - av_log(log_ctx, AV_LOG_WARNING, "Color primaries %s is not supported.\n", av_color_primaries_name(src->color_primaries)); + if (colorpri) + CVBufferSetAttachment(pixbuf, kCVImageBufferColorPrimariesKey, + colorpri, kCVAttachmentMode_ShouldPropagate); + else { + CVBufferRemoveAttachment(pixbuf, kCVImageBufferColorPrimariesKey); + if (src->color_primaries != AVCOL_SPC_UNSPECIFIED) + av_log(log_ctx, AV_LOG_WARNING, + "Color primaries %s is not supported.\n", + av_color_primaries_name(src->color_primaries)); + } colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc); - if (!colortrc && src->color_trc != AVCOL_TRC_UNSPECIFIED) - av_log(log_ctx, AV_LOG_WARNING, "Color transfer function %s is not supported.\n", av_color_transfer_name(src->color_trc)); + if (colortrc) + CVBufferSetAttachment(pixbuf, kCVImageBufferTransferFunctionKey, + colorpri, kCVAttachmentMode_ShouldPropagate); + else { + CVBufferRemoveAttachment(pixbuf, kCVImageBufferTransferFunctionKey); + if (src->color_trc != AVCOL_TRC_UNSPECIFIED) + av_log(log_ctx, AV_LOG_WARNING, + "Color transfer function %s is not supported.\n", + av_color_transfer_name(src->color_trc)); + } if (src->color_trc == AVCOL_TRC_GAMMA22) gamma = 2.2; else if (src->color_trc == AVCOL_TRC_GAMMA28) gamma = 2.8; - if (colormatrix) { - CVBufferSetAttachment( - pixbuf, - kCVImageBufferYCbCrMatrixKey, - colormatrix, - kCVAttachmentMode_ShouldPropagate); - } - if (colorpri) { - CVBufferSetAttachment( - pixbuf, - kCVImageBufferColorPrimariesKey, - colorpri, - kCVAttachmentMode_ShouldPropagate); - } - if (colortrc) { - CVBufferSetAttachment( - pixbuf, - kCVImageBufferTransferFunctionKey, - colortrc, - kCVAttachmentMode_ShouldPropagate); - } if (gamma != 0) { CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma); - CVBufferSetAttachment( - pixbuf, - kCVImageBufferGammaLevelKey, - gamma_level, - kCVAttachmentMode_ShouldPropagate); + CVBufferSetAttachment(pixbuf, kCVImageBufferGammaLevelKey, + gamma_level, kCVAttachmentMode_ShouldPropagate); CFRelease(gamma_level); - } + } else + CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey); return 0; } From patchwork Thu May 30 01:16:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Scholz X-Patchwork-Id: 49379 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:5c1:0:b0:460:55fa:d5ed with SMTP id 184csp6702vqf; Wed, 29 May 2024 18:21:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVy5lLGRKPwlAFDy9+/XLXA+lGd/1y5p3x3EUzAae5z8isHZA5/14i9SfiPv9kgWWlHJp2TRiJuEjXG0EhkxOhBtV9iSrNXIN8Tpg== X-Google-Smtp-Source: AGHT+IE/xBrIJzL1NNPw2mSYXem/YE1OsHsntUXu6E0CKE4dHQwyD0tpeSYS4oIInUjpgejmw71P X-Received: by 2002:a50:d79a:0:b0:579:c2d2:fa4c with SMTP id 4fb4d7f45d1cf-57a177b5325mr345804a12.3.1717032091573; Wed, 29 May 2024 18:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717032091; cv=none; d=google.com; s=arc-20160816; b=yIO0fsxId5EP4q3+3tMqG+AtE/E7Mx79OiQlaKqq3GqDmcxi7BveGBRy7cNrGo6V3x wXnZMQOQ4UDCGjhHb/Ecyy7RQock0AR/0cs3eiu3QJzbUyWu1hHaOIpfRufXd1zWfigO zXzjUSVQf7vRAIP57SzxKeFFuAkGoS9tg55fE0cIIDAn4XXfIZW60CTx8dN8SvTly4QX IdebPYOInBTrM1eiSeB/7hsxprt1zu2ByvciLKYUU0PaKOsdqxDamBl/ZEZMzoaqH3IK 6HyQOKE1WrP0oDC9TmU9+RA8NFy0Ti3iJDvOplezFRd3jjl3Dx58a/cOfcCo9sUU0Ksp /F2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:date:from:to:message-id:in-reply-to :dkim-signature:delivered-to; bh=ZYZNPL3NqgTpOpj5ABdPWfB3LrOEqz0iNQZCtsmyIcc=; fh=5IeVwzS1vbVKjIV8MP3mnmnRtZGb8uteQ9r4QD2keV0=; b=ANMMMOIEbAgKeN154UjaK+8t2w00a25btFu7IU8ivwH2WK0NoZ7J3bEFm+vjDV5Fi0 I0jzGDZ5gxLU3cakvw+0RP/tHtY4sDm84/lbfrjyumtBN9wUoBZor0saL5nEJWgk2C04 3u4NQqtj/Hp2BoZRVd8pTLclbXqZ28FCnbSyT1TfWjyIrm5vdC8ItD9jDquaBAz2rp6F umffMNBmRqZvb1jnCxQTpJqnkES+V1OUijITL61gJroKR0SJLPjwkvPa+DqxLrFq8tDF AxymDYgcFzmjRg+QzUAmmqnH1NTdeYp1BNCFnDxieUhC4rrLBGyHfp6OO3a/hl5ejlRA Pt7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=GGY47lIm; 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 4fb4d7f45d1cf-5785247b875si6370891a12.380.2024.05.29.18.21.30; Wed, 29 May 2024 18:21:31 -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=20230601 header.b=GGY47lIm; 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 CDDA968D509; Thu, 30 May 2024 04:21:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE4E068D0AD for ; Thu, 30 May 2024 04:21:12 +0300 (EEST) Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-578517c7ae9so276737a12.3 for ; Wed, 29 May 2024 18:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717032072; x=1717636872; darn=ffmpeg.org; h=subject:date:from:to:message-id:in-reply-to:from:to:cc:subject:date :message-id:reply-to; bh=C2gNout6Y2AN9003hXqSFyJ8BCKIfshELKwLmdlTDA0=; b=GGY47lImyvQBdBmqz6pCOtcmbnLv0e/Q9Ngh3YMV7VKGdj/o8s0zybKyZriTrzheOX krgAUQdzxhW7Gh9OgDLQ111faFW+yp3E19BJSP1Ypzyq7g3JCVTX2oXpnyAi9xj4QBoX MQzgfAWWFtDEuFZ1lDFL2GzF5f3DymJ8ek6TupqUPP4ZvcPQVK7n5B4L/Uq54ommjxXA ZyHlQ6eY3V3IQXKj2Yk1WHwVC3eBGTHMpHBc9/iLjIGLS3/9+0hEQPykIXFSKgRk/2El 5k3KuHz0fIWn2Ga8XAW1qSpQvFqClvFRyuZS0z5BmBCdYMiymm0jIiUf+53Y7cYZOXkn v3dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717032072; x=1717636872; h=subject:date:from:to:message-id:in-reply-to:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=C2gNout6Y2AN9003hXqSFyJ8BCKIfshELKwLmdlTDA0=; b=i8+2N7Al9lRJAAG7O5gZVXgJaXaIt8dbPAc5YFsoe8HqtG9r4rJ9VYl7Q1dv7zmPz1 KaZRCupwEYIX9cqBa+DX+i3lAfbioe5YJzKM+QNhr2zBqM1i4Fd3xJhMSOjrYh1/qhDz RoMNgk8PDXh4GDwyL35sB57vdFK6+IEvj/2dJO9coNEfqCrh/IWKRBEg1MoKM4Urnq25 44E1J152Ilq7ZGq93XOdvcgnhwWYGUTDwVov8T3DafEk1s5qFiIAf8QUONisxERmuaS/ zVRNDLOOzZsCcenNpqf+BxuTJ9WClcRgV8jdBSirmhmVUMVIjHRk4tS7DUNlg6BKKLUW 8XWQ== X-Gm-Message-State: AOJu0Yyrk8/oiVZiRkwouqU+y+tzvxbD6V9TyWzW/ObVI1K6AqzeWovS v/cpycrgkFHTQV+mrwUXlNdOp3/ix6rodzelf3aj008oo3D+R9mkc8pWEw== X-Received: by 2002:a50:bb42:0:b0:578:c161:525d with SMTP id 4fb4d7f45d1cf-57a17871cd6mr346950a12.25.1717032072074; Wed, 29 May 2024 18:21:12 -0700 (PDT) Received: from localhost (p200300cccf0f49001441a6a3c951ef29.dip0.t-ipconnect.de. [2003:cc:cf0f:4900:1441:a6a3:c951:ef29]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-578523cba01sm9160400a12.35.2024.05.29.18.21.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 May 2024 18:21:11 -0700 (PDT) In-Reply-To: Message-Id: To: From: "Marvin Scholz" Date: Thu, 30 May 2024 03:16:56 +0200 Subject: [FFmpeg-devel] [PATCH v3 2/3] avutil/hwcontext_videotoolbox: Update documentation 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: hAU0Xjx/d5n4 The documentation was not clear at all what specifically the function does, so it was left unspecified if it will unset or not touch attachments it could not map from the AVFrame. The documentation of the return value was wrong as well. --- libavutil/hwcontext_videotoolbox.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libavutil/hwcontext_videotoolbox.h b/libavutil/hwcontext_videotoolbox.h index 600e9f2c8d..d35cfbb6c1 100644 --- a/libavutil/hwcontext_videotoolbox.h +++ b/libavutil/hwcontext_videotoolbox.h @@ -90,8 +90,15 @@ CFStringRef av_map_videotoolbox_color_primaries_from_av(enum AVColorPrimaries pr CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteristic trc); /** - * Update a CVPixelBufferRef's metadata to based on an AVFrame. - * Returns 0 if no known equivalent was found. + * Set CVPixelBufferRef's metadata based on an AVFrame. + * + * Sets/unsets the CVPixelBuffer attachments to match as closely as possible the + * AVFrame metadata. To prevent inconsistent attachments, the attachments for properties + * that could not be matched or are unspecified in the given AVFrame are unset. So if + * any attachments already covered by AVFrame metadata need to be set to a specific + * value, this should happen after calling this function. + * + * Returns < 0 in case of an error. */ int av_vt_pixbuf_set_attachments(void *log_ctx, CVPixelBufferRef pixbuf, const struct AVFrame *src); From patchwork Mon May 20 01:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Scholz X-Patchwork-Id: 49380 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:5c1:0:b0:460:55fa:d5ed with SMTP id 184csp6772vqf; Wed, 29 May 2024 18:21:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWBC3T+7/13wK6OnqwOheYEJqBO+uSgJr1xSLPPDItTaRaAlFwnJvtgnXYc0KnJj+06tRvO8P2GGbkW7FgHxxOr3KboyAfJtwpSTA== X-Google-Smtp-Source: AGHT+IEwREHSaHM1rzVCfOOskVKSNMoD1hPtodyAXIX4NNcVIuljKmXMKpUQjgI9icSsRCpAQT90 X-Received: by 2002:a17:906:5a6a:b0:a59:a0b7:1850 with SMTP id a640c23a62f3a-a65e923ee36mr41778066b.5.1717032099923; Wed, 29 May 2024 18:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717032099; cv=none; d=google.com; s=arc-20160816; b=lTW2aUZh4TeHUyr8V15BrokoalxdFpPnAm0cygWjxfRYRNPw/89+s6dA2mbVfQXj6X I3sM1+4WebcoQx9jdTIttwI0ul8qU/3AWiTrCZjFboYyFOI5KrQy+u/GP+zGlxf0nmS5 J+zi7cmMskZ3mzjcgej9uP/MXCeHvKOClh+mUtvNMYykzlN84ahFi6SmR9/PoV/eH4Rz peCaLOu4g2AQifplvOvGooR3z10bVDZBXEGX81OFj71T95hykLhdMWq0LH+S/+vxSqpW 7LnX2ThK6ZnFcTWMcUNXpIUihwMHcWeQ4cAyRIRrkFK9ZppXrZYpwVaN5CpTc+UBTCpU xdsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:date:from:to:message-id:in-reply-to :dkim-signature:delivered-to; bh=Mt81FWHuN/qhxRKDTnCBjA7wPZxwhZHaw1BK1Es69PQ=; fh=5IeVwzS1vbVKjIV8MP3mnmnRtZGb8uteQ9r4QD2keV0=; b=bPjmGyuXvyTDV4IykPIVlqhY2QU3nVWL5yexkRZLAWhV8/kXJkSdxiTlS6NI2CUEa3 W7y06V0/yTWIW365i+9ysn8yJrK52HYKxx488VLgaLlfBoLLZkxq7BqnYEwKbrW7BYK7 I9rFhobXpogMUSmDkyVcLbnkRdIOOOJtC75+SAbq0VizKreGDVFlSctbPP06GlhkJvaL m8/aCRosTTTf632f92ymiB3V90GkP7QDreEIrkDvCd17A4nq8QFU6JJKIDVgoEta/RSm b5QqEXnugu9ndgjNzrEmnfUmoK9bGF3jpD+1OAgPxzcSM8z50BH2a/M3cwe8quJXQ8wA R+rQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=dQESKGcd; 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 a640c23a62f3a-a632fbb290esi309080366b.935.2024.05.29.18.21.39; Wed, 29 May 2024 18:21:39 -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=20230601 header.b=dQESKGcd; 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 4B8A868D535; Thu, 30 May 2024 04:21:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7AC1568D428 for ; Thu, 30 May 2024 04:21:14 +0300 (EEST) Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-355080e6ff9so356746f8f.2 for ; Wed, 29 May 2024 18:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717032073; x=1717636873; darn=ffmpeg.org; h=subject:date:from:to:message-id:in-reply-to:from:to:cc:subject:date :message-id:reply-to; bh=oCer7xXb4XZWxud7cevzndRCucf0ZcGicelCbQd2hjI=; b=dQESKGcdf6ZmrPNk/4IVCVzHjgoFvcfObSBdhm4Huimbk6APeR7DI98scB1u8+EGC+ mfV6F4uhwDvtInEWuVHDO6k2G3/1gmoT6dBcHzK5vyy0OSz2PdCzkiVqhqEYllsooVDA VMdTWSzIMFu6WBoL4WQaRdQB+ToAuCdurr+OAfC9pEMh2YZP+CP23N43Nl2xiDf0sYfv g0DG9MiDL65wHIsK1enrC+iScQMMJrnBJTO5a4XUElCGvgGHnPpC3xr21E1iCSmh2Ghv S9+J8XcfkcsZgvWjePr2Vlua5Ef+Qj+x7vp9HRxZw4utbGahrybBRve8wwvZvHUDkyxT Fsqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717032073; x=1717636873; h=subject:date:from:to:message-id:in-reply-to:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oCer7xXb4XZWxud7cevzndRCucf0ZcGicelCbQd2hjI=; b=E9l6PvSn/ts4RSDk7ZpllE5vcqRWQtotdN9UErP3/RfnTKwutv/mvcMnzX3xlTKUEG jnABowdTIGtrSD5HPdY3QsPwwDAI4rLygz3MsiNVXKRWzRLfDF31EmPg4O1amznS1j7T Os4RBdMLTcr+plw0PPU/rxbYn6kdTU0tlBy7OD32yK3Wnw/yLly/8bEvT11XnriIYFsm oEW1ePM6Dx9D8fAYh4XESfmTci+LysGwpQwqsokPSig26xiJ7GT9VRsxZVA3tFTGkhFf KGu9Bj356G1m1nZXv4a8FIUsHnQljybspiqENHxrUvgmCSuy/RSK0R+Rt+TNudHFQ6xZ nA6w== X-Gm-Message-State: AOJu0YzYe0AMYZk8oT02zEDdwd/IHWGmAShW4DhwESoKFnkYbfjKva5t E6QFEbYGdoKgZd+bXYJxQ6K3WNwhd8M9XC/ufJxD4Rp/iv62ve0qAkL4hg== X-Received: by 2002:a05:600c:3caa:b0:41a:41c8:d8e7 with SMTP id 5b1f17b1804b1-4212780a849mr8030455e9.3.1717032073121; Wed, 29 May 2024 18:21:13 -0700 (PDT) Received: from localhost (p200300cccf0f49001441a6a3c951ef29.dip0.t-ipconnect.de. [2003:cc:cf0f:4900:1441:a6a3:c951:ef29]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-578523cba01sm9160400a12.35.2024.05.29.18.21.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 May 2024 18:21:12 -0700 (PDT) In-Reply-To: Message-Id: To: From: "Marvin Scholz" Date: Mon, 20 May 2024 03:12:01 +0200 Subject: [FFmpeg-devel] [PATCH v3 3/3] avutil/hwcontext_videotoolbox: Set CVBuffer CGColorSpace 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jcO5Qs/OnYKs In addition to the other properties, try to obtain the right CGColorSpace and set it as well, else it could lead to a CVBuffer tagged as BT.2020 but with a CGColorSpace indicating BT.709. Therefore it is essential for consistency to set a colorspace according to the other values, or if none can be obtained (for example because the other values are all unspecified) unset it as well. Fix #10884 --- libavutil/hwcontext_videotoolbox.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c index 0af2ab822f..953155ce32 100644 --- a/libavutil/hwcontext_videotoolbox.c +++ b/libavutil/hwcontext_videotoolbox.c @@ -535,6 +535,7 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteri static int vt_pixbuf_set_colorspace(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src) { + CGColorSpaceRef colorspace = NULL; CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL; Float32 gamma = 0; @@ -587,6 +588,21 @@ static int vt_pixbuf_set_colorspace(void *log_ctx, } else CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey); + if (__builtin_available(macOS 10.8, iOS 10, *)) { + CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf, kCVAttachmentMode_ShouldPropagate); + if (attachments) { + colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments); + CFRelease(attachments); + } + } + + if (colorspace) { + CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey, + colorspace, kCVAttachmentMode_ShouldPropagate); + CFRelease(colorspace); + } else + CVBufferRemoveAttachment(pixbuf, kCVImageBufferCGColorSpaceKey); + return 0; }