From patchwork Thu Jan 5 10:41:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitrii Ovchinnikov X-Patchwork-Id: 39881 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp282862pzb; Thu, 5 Jan 2023 02:42:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXtu095zTDBLJZmO1EXLEWlURzsEvvlKJ3n2XCa8RJIzhBzatMQu1agmxSP7cbNpspSAstIr X-Received: by 2002:a05:6402:b91:b0:487:1a83:a6a0 with SMTP id cf17-20020a0564020b9100b004871a83a6a0mr26430966edb.13.1672915339211; Thu, 05 Jan 2023 02:42:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672915339; cv=none; d=google.com; s=arc-20160816; b=jffZkWjq/N+TZcAPV0wvDVnPSF+f55dHfa9TXdfVwLObLKrqWkQ2jcyQtbgpQAChxN iVDJE+ffZoMyjtxjPx/IBUiU/GKwCHu+4FqzHw6uUPn6gNb1SThZGd7veAq4L+ZiM7l+ 4CrPEMcT81tZvxM1Vu56xe/IbI4j6xhWAYlwZsI08OoPnqwAUiOAMPQkac36SQZpvXYy LOjvjhyL5Vak+KVTbuYHTJ6xoGbMUNFBv+caXcsaIS+LWuE7QpU7I4u7FnvwSb9ORHZO 0sj4qzXpZm5Nhw1b53Fz0ZgiMdp0OZB5oAiETR9nh3TES4rU7WmxzfiQVtXDeNf+bhoA 8jwA== 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=Hmh7oJK1RPNoWIjU+PGh5PowYl6xjNtGR0CjgEy7DMs=; b=tOET6VxQDVDvFMHExeBhmNA+G87Q0Cj9hXsGGKNfYm1SrohYBw/b5xLyYxWcr64hPd 863OCwVuXXmoo6UtMD9gaseGtsTaimx9xtdzDR9HpKAgPVi+xuju+GTg2SFy7iOdELi/ D+upu/KgRBteERyG0lo61Xa3gr5TXbFXpAbINClQUvFC62bMJHrKhVtCIQzW9REMRpB+ zxkue6di0tPMdfR4X7hxA+MGh/oWbj0MmBtrWVJLjrMdA34MPR+jOd2wh30FS2uiQV51 gTezuJA2L3Xn+BUoW9GI8GTt4sehwCz/8qMGQ8pUNxKbsv42pSKlpM9zdxdr4Qd+Q+gX 1MCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=WVdzuXu0; 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 z11-20020a50eb4b000000b0047f3dfa596asi29189288edp.162.2023.01.05.02.42.16; Thu, 05 Jan 2023 02:42:19 -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=@gmail.com header.s=20210112 header.b=WVdzuXu0; 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 73D8E68BC7D; Thu, 5 Jan 2023 12:42:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A827768BA1C for ; Thu, 5 Jan 2023 12:42:06 +0200 (EET) Received: by mail-wr1-f50.google.com with SMTP id d17so15940214wrs.2 for ; Thu, 05 Jan 2023 02:42:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jTxwezRDRgzIDl6gkUiyB8Z/Wmgbczpox7LQijnnT0g=; b=WVdzuXu0d57Ew6o3KIrvzLp6qB0MXKjbEH69kzL5zfoXqkTGVgb9jlzoWjxfD5fAcT ArOEZPdGvtVahgfHtV4fSIMIhH82/MWcpvXWM/oryCQN+UMv4b76sMSlB0NNRfOkNp4a EfYmcqyQeAfuu+Jl7Vac+n814qIwOOZI+Zq5EAJaEgbHMF72QLiRqaJA6R6klFmSVr+g G8Kf4ZSk9/hs4DgKvNDEQcZi0nH7VpfX9vxGZxOxO8HNe9wTkznS9B/zbljEn7L776ZK CvciSo1CTSlRQEhR6yYKx2YV6oWbctocDqU0XQ8M5X1R2B9uku69gfGd4dGfrHEp6qcq tpjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=jTxwezRDRgzIDl6gkUiyB8Z/Wmgbczpox7LQijnnT0g=; b=16iPRyCPeuUfo6EjSS1ipG7cTrGcsqxqG3bOgQKAnRlLHJyCeaLMSjcsI8TYay3/3o cFv1VtKziMstaBrQX9/h5iAanYb7QjJF2T7Zf9muaqDH85UoTyShGlwhLJrCqBMonceM 2JdgQx7qJj38dni9feAxUmgiV3mUPmaDmg0iRK67zQqEbZ+vUENnLImwItcmBhJYzKoM +0R7fU+qrb4lMeoYo1ssJods7EMNZclJiZ6Tc7pTyqfMlMNaN0jvgNoG4vwkN0aTsU6j HuKXox0a+IyfiDpx4xuAcovDi69rQbUDYTATiG7/LL5s+noVAON2GKLC75uFW1/t82ps QECQ== X-Gm-Message-State: AFqh2kqIu+tv8lseLELtm5DWUMr+eEBrSup8HM8i4efUeENeeVrf9dRy aaFp8oYIpixYRNPeAttMmUGI3K6o/WM= X-Received: by 2002:a5d:5304:0:b0:2a8:e91d:ad2f with SMTP id e4-20020a5d5304000000b002a8e91dad2fmr2847171wrv.35.1672915325233; Thu, 05 Jan 2023 02:42:05 -0800 (PST) Received: from dovchinn.amd.com (109-93-70-158.dynamic.isp.telekom.rs. [109.93.70.158]) by smtp.gmail.com with ESMTPSA id a6-20020adfed06000000b0028e8693bb75sm21479067wro.63.2023.01.05.02.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 02:42:04 -0800 (PST) From: Dmitrii Ovchinnikov X-Google-Original-From: Dmitrii Ovchinnikov To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Jan 2023 11:41:51 +0100 Message-Id: <20230105104151.2055-1-Dmitriy.Ovchinnikov@amd.com> X-Mailer: git-send-email 2.38.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] lavc/libvpx: remove thread limit 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: Dmitrii Ovchinnikov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SKBay1ZcTxWO From: Dmitrii Ovchinnikov This change improves the performance and multicore scalability of the vp9 codec for streaming single-pass encoded videos. The current thread limit for ffmpeg codecs is 16 (MAX_AUTO_THREADS in pthread_internal.h) due to a limitation in H.264 codec that prevents more than 16 threads being used. Increasing the thread limit to 64 for vp9 improves the performance for encoding 4K raw videos for streaming by up to 47% compared to 16 threads, and from 20-30% for 32 threads, with the same quality as measured by the VMAF score. Did not need to add a check for limit in libvpx as it is already present in libvpx/vp9/vp9_cx_iface.c: RANGE_CHECK_HI(cfg, g_threads, 64); As demonstrated by following message when -threads is set to anything more than 64 [libvpx-vp9 @ 0x30ed380] Additional information: g_threads out of range [..64] --- libavcodec/libvpxdec.c | 2 +- libavcodec/libvpxenc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c index 9cd2c56caf..19407092d0 100644 --- a/libavcodec/libvpxdec.c +++ b/libavcodec/libvpxdec.c @@ -88,7 +88,7 @@ static av_cold int vpx_init(AVCodecContext *avctx, const struct vpx_codec_iface *iface) { struct vpx_codec_dec_cfg deccfg = { - .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16) + .threads = avctx->thread_count ? avctx->thread_count : av_cpu_count() }; av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str()); diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 9aa5510c28..0627e13973 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -942,7 +942,7 @@ static av_cold int vpx_init(AVCodecContext *avctx, enccfg.g_timebase.num = avctx->time_base.num; enccfg.g_timebase.den = avctx->time_base.den; enccfg.g_threads = - FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16); + avctx->thread_count ? avctx->thread_count : av_cpu_count(); enccfg.g_lag_in_frames= ctx->lag_in_frames; if (avctx->flags & AV_CODEC_FLAG_PASS1)