From patchwork Wed Sep 29 17:01:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 30657 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp565384iob; Wed, 29 Sep 2021 10:02:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxb7w8XoglPC7HH2ThOdPqGY46NV+TWvW/bHttMHEQHsmOrT17myK+141Kj99YFTMdSoaDx X-Received: by 2002:a50:d9c9:: with SMTP id x9mr1150558edj.179.1632934924373; Wed, 29 Sep 2021 10:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632934924; cv=none; d=google.com; s=arc-20160816; b=eJNG5K4Oor97l7TjaUFPdLoeO/e+aHPm+kr+bajOemMwLgJR3Ba9GrqdqhWM0H8vLH 9Q3qMDoh6XTjDbvLzV8gl7nCHebTyJt9G/wPvtTLmFWUfJSmgE3XRuai3wrLJd8RpN53 6CM/xUdTT2zZL9t9XFRifgKSbfUS7CevUF8QIBHU4+W7BoCYiLPUFNF1n5msdOrEyvYQ 8DyyryjL+wt4ijo3RzGDJ0SnFz/rJ/cftKfU8/x6BXkyW030LfEUZP7c0gXnk3KKHaY3 50IuvfoN1hpqkpW6fprL40HhiJ6ed9CRSsKCSPxmwUHRIirmfOwKOX603wwidUhcl3EE zhlg== 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=Ty/k2hkGQMATsGlQOLz9kfZgcmLCDyzF6hRs/xi3Zps=; b=QaW/paNQx6Fnrj0PTt323otppi8exriLc5s2tASQLxKX9yBIHeb1hg0K1xRJJjoTGC u5o7QjuCnVsQ0AC+DC/tLOREn07i5Te44ldrIBImMwVJsc1Gt79gL7bocGQDYZ73qBEP 57BLIciN/oUW3odEfFNS8ZQY75FAEL9efHn6a5mTaHo9Dv2dv7r8MCfnRVLW7aSg56k8 WWAl3Vbz6V1rjNisJi5EsM9jhZb1/8kuF4XBHO5pJKiki4SP37iiE5NuwESFOsaVljEs ebPYcjP9hUsiHn1FnHSzyks8ZZM/J9vFh8jCHvLRHTH4Uq2CRS0JaoaqT/3lGBZQpOqE 3P+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=mFi5dGEw; 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=rothenpieler.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id bs18si459815ejb.674.2021.09.29.10.01.58; Wed, 29 Sep 2021 10:02:04 -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=@rothenpieler.org header.s=mail header.b=mFi5dGEw; 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=rothenpieler.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5CF9B68A044; Wed, 29 Sep 2021 20:01:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [136.243.74.85]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C44FA680152 for ; Wed, 29 Sep 2021 20:01:47 +0300 (EEST) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 4FD242782C1; Wed, 29 Sep 2021 19:01:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1632934907; bh=i1kL7I1bHSOIBA10JmvhAgNcahYDBqjWX3cU01WGG3k=; h=From:To:Cc:Subject:Date; b=mFi5dGEwmGbe96kjGrQWaB3hsEceoiWjorgCpPxCBlXAIbwTQKma2K6xm1oL3LyxA wls2hrzCkIzhWZMjvbGeiuBKhaEAC91U8l6jJzs0tQ7lEtrQQ3Cqp2TZYNSPzY0uHA +YoyuRv8rUK0acnN98HJLbWrqZXMrMiH5ZYV70dgxdKR5or/owGAnVj8osH8wRuRAx BLa9DvLd6Gqq4/Scq8cjjgpaFMcnpNdqc6OSeT652Kjkn403qJyCuXrOLIGmpGb0Vt /fZHJCHDBHc4MuKkZB5YXhQKEp3vUTZjwVpzgAD2WpPxOnXB7kGJSjflbyIkHpFJzx dTx/gJ2kicE/A== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 Sep 2021 19:01:34 +0200 Message-Id: <20210929170134.29381-1-timo@rothenpieler.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC] ffmpeg: default to single thread when hwaccel is active 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: Timo Rothenpieler Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wm9tO3v3PJjT --- fftools/ffmpeg.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) Not sure if there is any downside to this. Threading for hwaccel does not make a whole lot of sense, and at least in case of nvdec wastes a lot of VRAM for no performance gain, and specially on high core count systems by default can even exhaust the maximum frame pool size. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 98c2421938..d007d55173 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2995,12 +2995,6 @@ FF_ENABLE_DEPRECATION_WARNINGS * audio, and video decoders such as cuvid or mediacodec */ ist->dec_ctx->pkt_timebase = ist->st->time_base; - if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) - av_dict_set(&ist->decoder_opts, "threads", "auto", 0); - /* Attached pics are sparse, therefore we would not want to delay their decoding till EOF. */ - if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC) - av_dict_set(&ist->decoder_opts, "threads", "1", 0); - ret = hw_device_setup_for_decode(ist); if (ret < 0) { snprintf(error, error_len, "Device setup failed for " @@ -3009,6 +3003,16 @@ FF_ENABLE_DEPRECATION_WARNINGS return ret; } + if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) { + if (ist->dec_ctx->hw_device_ctx) + av_dict_set(&ist->decoder_opts, "threads", "1", 0); + else + av_dict_set(&ist->decoder_opts, "threads", "auto", 0); + } + /* Attached pics are sparse, therefore we would not want to delay their decoding till EOF. */ + if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC) + av_dict_set(&ist->decoder_opts, "threads", "1", 0); + if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { if (ret == AVERROR_EXPERIMENTAL) abort_codec_experimental(codec, 0);