From patchwork Tue Dec 26 22:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 45334 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp3293845pzh; Tue, 26 Dec 2023 14:25:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXIj9+zuMLNuCePUVVpYjcrI6J/kDScsLC+UUQfDM6GsniuTcykDZDPJ4IS9SnzCMJ2kHv X-Received: by 2002:ac2:5dd5:0:b0:50e:410c:6a49 with SMTP id x21-20020ac25dd5000000b0050e410c6a49mr2707673lfq.130.1703629528422; Tue, 26 Dec 2023 14:25:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703629528; cv=none; d=google.com; s=arc-20160816; b=HF5HC/W7Xy0TdR8LlFq4eCrK6pseoY8ELj94XUc8fuzov/hRVZ4OJWFdG2GxdVgn1P MrNiIT/S3wsHg+OpdXYgDDCDHnlCUNSIsGrDfo8i4GGaopHI7t+y42ydZXeKiSFc+iWA 9uXuqS0pEXVoyXFbi7+iUO/T16FHDln4ZG7v/ztHLuc7/AzlD+6Fh4l9jx1sa0NqoSGf 6ArRw6A7GqpcTF0PMnmHsC6JnMZfYmtwHgfNrUpKVO8dYK8DLAf0UzAxdCzEPOOdUAgk iDJOu1yGgmpMqBHF7Ymj2DAoCU83lNj3luZFvQOgF5lRRzPW/FJsFieEZd/sU/5HFzwb SHlQ== 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=HDxn4lmM+mFMKC/hX2aZbS0xbR9Vf5kEkcoMHyYLeLw=; fh=Jgo3TCyoG8OdFLqA8BuM7Wbf1w27210JU6p+E8x39/M=; b=bZQWOc59b/tf4fmcvMQiqe6ZHxN7xR1qcHj1oiDj9IdFbh+19g6Oq3HZk12cR3rJEt nwWSb/yKsQg/nWHvXjXzgrQHn4N1iiI3adU4EvDBu4e0odsrfWXGIPXHVnG8havu+CKK V0Uu3AOGilyBmKh4xv0qKHSsD4/X6aEmqCUoJ2r/J9t05flxJ+VzYQBTs/0qL3/OFAoC CMRL1+W3qBkrNseAIuPkrPjLQLU7H6UPE87ZcuMqsysIJNjlLOGI2M7sTYMlFOwmjApl wbUA8kCF3REyTvtYWySpFll0vGwoU4yM8AE88rMiFLTJv9TKVmIgxhAsJzh1DhPRsy/b Rdog== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=YRg25Uim; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y9-20020a056402358900b00554b2c32cbasi2803539edc.97.2023.12.26.14.25.28; Tue, 26 Dec 2023 14:25:28 -0800 (PST) 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=@pkh.me header.s=selector1 header.b=YRg25Uim; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2E4D668CC35; Wed, 27 Dec 2023 00:25:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9DBFF68C671 for ; Wed, 27 Dec 2023 00:25:18 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1703629518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uHRou7IaLkn9DVcqgrl5TkGO5VekyLH/LeNgnFnJKCw=; b=YRg25UimsdiFWy/bzjNuRoZjSxNx9FZVRhDtalavQDqYgzpyfKhcsjBmXdeC3VNfVoJdQ+ 73GRWMOb6SxBlh8+Az3XQGcVUJIffFYVJaG2g6fNHObtZMiaASVaGxEsf90HPGoDyfOTHz rxosWU0JV5/B8J1aPxGAK29k6F46q6w= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id a1cb63ef; Tue, 26 Dec 2023 22:25:17 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 26 Dec 2023 23:25:15 +0100 Message-ID: <20231226222516.2513700-1-u@pkh.me> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/proresenc: make transparency honored in mov/QT 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GG6/+PCZjtqy In the mov muxer (in mov_write_video_tag()), bits_per_coded_sample will be written under certain conditions and is required to be 32 for the transparency to be honored in QuickTime. prores_kostya already has this setting but prores_anatoliy and prores_videotoolbox didn't. --- libavcodec/proresenc_anatoliy.c | 3 +++ libavcodec/videotoolboxenc.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c index a1cb46aa59..16741afd68 100644 --- a/libavcodec/proresenc_anatoliy.c +++ b/libavcodec/proresenc_anatoliy.c @@ -930,6 +930,9 @@ static av_cold int prores_encode_init(AVCodecContext *avctx) } } + if (ctx->need_alpha) + avctx->bits_per_coded_sample = 32; + ff_fdctdsp_init(&ctx->fdsp, avctx); avctx->codec_tag = AV_RL32((const uint8_t*)profiles[avctx->profile].name); diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index 15e0e1fe29..644fd60b00 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -521,6 +521,8 @@ static CMVideoCodecType get_cm_codec_type(AVCodecContext *avctx, } return kCMVideoCodecType_HEVC; case AV_CODEC_ID_PRORES: + if (desc && (desc->flags & AV_PIX_FMT_FLAG_ALPHA)) + avctx->bits_per_coded_sample = 32; switch (profile) { case AV_PROFILE_PRORES_PROXY: return MKBETAG('a','p','c','o'); // kCMVideoCodecType_AppleProRes422Proxy From patchwork Tue Dec 26 22:25:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 45335 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp3293882pzh; Tue, 26 Dec 2023 14:25:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxK6bBJ2Qzdj2QuhBoXY8kdcGJCUM7NP+tkr9uSSohwa400KJwmLO8Qxi90eyaPaGTj64S X-Received: by 2002:a17:906:f5a1:b0:a26:d233:80b0 with SMTP id cm33-20020a170906f5a100b00a26d23380b0mr8010154ejd.0.1703629537024; Tue, 26 Dec 2023 14:25:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703629537; cv=none; d=google.com; s=arc-20160816; b=II3kuH3n/KsTkcxNI2OkmstcvHRdBo6BRkZRBJJic5aSlHkWsDwnM49MK0ftU2NpUL nBI6t5M1Udd7RNDM3zhxDKyaQRmRDn9BEfByknCSYlMyxxLQaHpqOXL2ckDwjUXxxp7/ n3OpUFYU7oSvWiNFrp8Gcaw7zgOAkggFwc5OV3PJatQmYwRyMAmxiqDajZ4rANfku84D IQR+U4BTZM69eX6AXSlr/r/YGqCqERyjEQ1T6gwnk/wFy1up/Obr+d/Dmw/6LCBt4JUf FgEwjgnoK5C2uqLWm1hYA9wDM8J+BvifOFP/Z2appz7Xl6+PQQ7OiA6fMTeaocJLQpq3 cZhg== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=s7UTE4IfsprtKYbEfC3Cww9/amnlu9EYoOjMj5XVA4s=; fh=Jgo3TCyoG8OdFLqA8BuM7Wbf1w27210JU6p+E8x39/M=; b=IVaxZbJGvYfz5vXn7DkoLOtA4dpoYZ8LauL7SA/CxFV7gJ7AdZ2tbqd4/mGPjCmcyp PYm4okba1pnRhhcViajc/LkcryWh88QIicRub3E9StBdaXSQ1X9swQw/tqJrA5Pd1R1H p5SFU/+jkZhqB9uxK1JTeuifvBnh9BlTrI/EqmKCVVX2A9C7e486kRvEqmcOXlQs+76z JiBnpaUTynQ3K6t5I4M1fRHwDQeOthiCBR+TXyYcmzmNa5sMwWthIsRF4I6Lx/JOWTd9 jNj06mEYlHYXe4yi70cviAxtjM1aplPzqsOPD1wjiixgFn3NKwGQCL2x/GZlRbJOXYzB xjhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=nxh74clI; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l22-20020a1709067d5600b00a2355010ba6si5398266ejp.1033.2023.12.26.14.25.36; Tue, 26 Dec 2023 14:25:37 -0800 (PST) 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=@pkh.me header.s=selector1 header.b=nxh74clI; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5EBBF68CD39; Wed, 27 Dec 2023 00:25:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CF73F68AA4B for ; Wed, 27 Dec 2023 00:25:23 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1703629518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oF5rdIY6QCR0UDX22yaozFRUFLkb0++zwKFZdJ+rj+Y=; b=nxh74clIrDaHOZm21qjUm4AR2DpJw1izpSoedDlqE5EYbvR4Xbhw6asD6cxwxFE5skySrt HNWYTbUwXbRd6kmABtKH2N2Rns/frnSH7IR8NZevVB1oDvWCA/8DsUCrzOOW72L5lA65hW YV65vudOjI13oI8lsLJiXBbrdF79kw0= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 914653c1; Tue, 26 Dec 2023 22:25:18 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 26 Dec 2023 23:25:16 +0100 Message-ID: <20231226222516.2513700-2-u@pkh.me> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231226222516.2513700-1-u@pkh.me> References: <20231226222516.2513700-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/proresenc: fix alpha plane encoding bitstream 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dv9p4kgzvL3S These functions encode a slice of alpha (1 to 8 macroblocks) which are expected to be encoded as a repeated sequence of "[diff][run-1]", where diff is the running difference of the alpha value and run is how many times that value is expected to be duplicated (within the limit of a grand total of 2048 unpacked samples, corresponding to a slice of 8 MB). Even when run==0 (the run variable semantic is actually "run minus 1"), there is always a diff previously encoded that needs a counter of at least 1. This means we need to call put_alpha_run() unconditionally at the end of the bitstream to account for the last running diff. This commit fixes glitchy playbacks on QuickTime with M2 and M3 hardware (but not M1 for some mysterious reason) with files generated with commands such as: ffmpeg -f lavfi -i testsrc2=d=5:s=912x320,chromakey -c:v prores_aw -profile:v 4 -y aw.mov ffmpeg -f lavfi -i testsrc2=d=5:s=912x320,chromakey -c:v prores_ks -profile:v 4444 -y ks.mov The glitch expresses itself deterministically as blinking black rectangles on random frames (for example on frame 21, 54, 71, 79, ...). Even with the proresdec from FFmpeg, overreads actually happens while reading the run-minus-1 value (around val = get_bits(gb, 4) in unpack_alpha()). This doesn't seem to cause any particular issue because it simply overreads into the next slice, and because the decoder is resilient, but it's still a problem. Fixes ticket #10255. --- libavcodec/proresenc_anatoliy.c | 3 +-- libavcodec/proresenc_kostya.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c index 16741afd68..9b9ffa03be 100644 --- a/libavcodec/proresenc_anatoliy.c +++ b/libavcodec/proresenc_anatoliy.c @@ -486,8 +486,7 @@ static av_always_inline int encode_alpha_slice_data(AVCodecContext *avctx, int8_ run++; } } while (idx < num_coeffs); - if (run) - put_alpha_run(&pb, run); + put_alpha_run(&pb, run); flush_put_bits(&pb); *a_data_size = put_bytes_output(&pb); diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index e904632f8e..8d45e42d1a 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -562,8 +562,7 @@ static void encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, run++; } } while (idx < num_coeffs); - if (run) - put_alpha_run(pb, run); + put_alpha_run(pb, run); } static int encode_slice(AVCodecContext *avctx, const AVFrame *pic,