From patchwork Thu Sep 2 10:06:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Chelminski X-Patchwork-Id: 29950 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp129630iov; Thu, 2 Sep 2021 03:08:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHiK0fd8aIBvQAEyCAdJJ0WlpfbusLr6NgrWafF02FmKXPDbOC5a8y2HHNhowt/WTEkn5D X-Received: by 2002:a17:907:9602:: with SMTP id gb2mr2952802ejc.119.1630577302734; Thu, 02 Sep 2021 03:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630577302; cv=none; d=google.com; s=arc-20160816; b=DCecfw0Hhs0mpPi8qCrpx9QLD8T/3uhyJzYB5AhjQCOPw0PdZ41TFApnbJXELR5VrY ITO9lCBh3htx7dE9bDi2C99l5BS4vl3Jyg5ngJ99Uy++Vnq9DumfBVf90pJCUcFjlebc WS/mFmjNfmlpLSRNHkSN1lsliBxisxE/BXSqEM+xvVSqUkXDybsMSeKwDNC9EkU0LUDA 8kFbFoZbso4QH+NC5Z/O9XkmLRcQFKa14ljnrPZyoQFrLKyfJ41qqJM+8CQu4ge4gXl0 UGhikgqkOtZdnC0nNRUC8rLK6Xa9wfZ+KCZmD/0kZJz6d0d28fRs279G7cDPtPEFsxt2 3sxw== 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=P+uBRS5HIe15QXETfWUPRugWdLAvuIpLQOW96btTyBU=; b=kOfoO698Frd3FyXvxkAq39VGAEjXSp0YXDVfUF20iz9NxDoXWJEwKthpt74m5IUCo1 q8+70lQojO2qSRCZZJWzMF7O81CXUwVcvvgOR23C/LupWP4BWp0tRpMqrBA9MeObG05X mDuwWsjKNCgNvijAMKFx6RhDy1nqu0gnqE2ahrP8IVQN3WN8Ivax/PrEWGYL9P8qj3GI AjJmv3Za+yqiL6vHhJQ2HXtkLm28J8IrogMht8z5JlFE2rpwknqByJk+Pd/tLqkss9z5 ipVnsJuYSx1cxFsns7x/HhdDdRl1h4g7pYaJw72+qxZu7d0KtviZI+LI0+e3SY6U7JbK dOrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Rt85fsE1; 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 i5si1384829ejo.475.2021.09.02.03.07.59; Thu, 02 Sep 2021 03:08: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=20210112 header.b=Rt85fsE1; 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 C83316802E4; Thu, 2 Sep 2021 13:07:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0F09A681871 for ; Thu, 2 Sep 2021 13:07:47 +0300 (EEST) Received: by mail-ej1-f54.google.com with SMTP id n27so3056933eja.5 for ; Thu, 02 Sep 2021 03:07:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dwnt8ctBJymtcYGpoDxCBF2vfqkugwBeRGoj8vmRxEo=; b=Rt85fsE176a8eRHVU0Bx75tzOuSzPcFSMa0eoRpdGY/VrsbTBuDgrRoQ3E1U4fZadK Ql6ziAXnDUwksfYuHxjwvnc8CY5klrMnpWg6f+JY3NZyXg8aCPHvksgp4YCJ/NkbTKRy R5Xl338CNwXd8UcVeDx3zpLuwUZW9ktpSM5utTEC+SjmckMSfEsvbHvabKfqm6bk09MT OmQXW+oNQ4hwmYW7Dy7K9VNzeFhjQsNRCntuxtp2K43f6wGGu8i3EpyIfpu92/0efEV/ ZnXPIn5PbZM9kOPwzKq7e+p5clfFE25pYjSmhgtxKMpT8r82X4/n3kqQt/hlMOb69hA2 JOtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dwnt8ctBJymtcYGpoDxCBF2vfqkugwBeRGoj8vmRxEo=; b=iTFcNrDEx2++ZYLzDQvyr9EV3c1ivxGFkohUIX2tiXEW8xuVm79X0q0sDdj6e5LPRS gHqcsowF2K8Vs7w5DeEvz8dd+W8UsIFsafin7QsjBmPeXMoqQcv3NqkqmbPTkud+Ofll La/ge0G3pSLXRuhAXGUIaiZwjpzqjMm7R22Or8ymeRviW2xL7yNuEqQ1gv+j9duBhjK1 l1Gs+VNudLMzsRbj2Q6Lmep6Xv4LL/DcJt5cbvGu0n5+lIYH+/SZMdaiVUiCslcvZczj cRP7j+4nbTmtHCdbu/oYot0HQ9SSPJMdwZHANC/Do4l507trz9nEfYRLybnqhRIIVU6w xuIw== X-Gm-Message-State: AOAM530PkQh12qHzuev2b0myGM/pqPdoFq9cOOauFgn1WcXXxo4+Nk8Z 6BpTr1QihDUe+Ij49iGYQ6qVdJEBZS8= X-Received: by 2002:a17:906:dfe6:: with SMTP id lc6mr2929316ejc.210.1630577267100; Thu, 02 Sep 2021 03:07:47 -0700 (PDT) Received: from localhost.localdomain ([194.62.217.85]) by smtp.gmail.com with ESMTPSA id b2sm826553edt.74.2021.09.02.03.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 03:07:46 -0700 (PDT) From: Adam Chelminski To: ffmpeg-devel@ffmpeg.org Date: Thu, 2 Sep 2021 12:06:56 +0200 Message-Id: <20210902100656.991238-1-chelminski.adam@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/libvpxenc: Apply codec options to alpha codec context 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: Adam Chelminski Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: hmkxv0Gpo0mS When encoding yuva420 (alpha) frames, the vpx encoder uses a second vpx_codec_ctx to encode the alpha stream. However, codec options were only being applied to the primary encoder. This patch updates codecctl_int and codecctl_intp to also apply codec options to the alpha codec context when encoding frames with alpha. This is necessary to take advantage of libvpx speed optimization options such as 'row-mt', 'cpu-used', and 'deadline' when encoding videos with alpha. Without this patch, the speed optimizations are only applied to the primary stream encoding, and the overall encoding is just as slow as it would be without the options specified. Signed-off-by: Adam Chelminski --- libavcodec/libvpxenc.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 0e50fbfd7c..1df0a8343c 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -385,9 +385,20 @@ static av_cold int codecctl_int(AVCodecContext *avctx, snprintf(buf, sizeof(buf), "Failed to set %s codec control", ctlidstr[id]); log_encoder_error(avctx, buf); + return AVERROR(EINVAL); } - return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL); + if (ctx->is_alpha) { + int res_alpha = vpx_codec_control(&ctx->encoder_alpha, id, val); + if (res_alpha != VPX_CODEC_OK) { + snprintf(buf, sizeof(buf), "Failed to set %s alpha codec control", + ctlidstr[id]); + log_encoder_error(avctx, buf); + return AVERROR(EINVAL); + } + } + + return 0; } #if VPX_ENCODER_ABI_VERSION >= 12 @@ -407,9 +418,20 @@ static av_cold int codecctl_intp(AVCodecContext *avctx, snprintf(buf, sizeof(buf), "Failed to set %s codec control", ctlidstr[id]); log_encoder_error(avctx, buf); + return AVERROR(EINVAL); } - return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL); + if (ctx->is_alpha) { + int res_alpha = vpx_codec_control(&ctx->encoder_alpha, id, val); + if (res_alpha != VPX_CODEC_OK) { + snprintf(buf, sizeof(buf), "Failed to set %s alpha codec control", + ctlidstr[id]); + log_encoder_error(avctx, buf); + return AVERROR(EINVAL); + } + } + + return 0; } #endif