From patchwork Thu Jun 7 23:43:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 9319 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp195603jad; Thu, 7 Jun 2018 16:48:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJmcRDP7Utp8sONZYUg5T1ApBbvBJhGBiC2/zrCdYvWE1gSJxFnl4CuM1wE/ewesA4GB0li X-Received: by 2002:adf:c444:: with SMTP id a4-v6mr3387979wrg.20.1528415309016; Thu, 07 Jun 2018 16:48:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528415308; cv=none; d=google.com; s=arc-20160816; b=AItx/a108otsX/ZVTGhyZ9SwMjrDsKHzHU90XjSdigV+QEgOJ6PLJvnSkvV8OCqP3X 6X+4hyK2F4zZls/qvTCoz/nMMY2njIaGuR2bA4uatoLsCtkrDiCGDuIV/qrsBFHhxAlK H5jRJ/H8XpdzxTYkB93Wf4Whxt3Z0ru6Jgaz82SQZX4VoXeoOBC4LDGyN3VIsVlfXGkN noJLCESa5ibbWnQyxbhEqQfDfghgrftVkE2354P+QK78FcLxPd2w8aBCkriqCIUzH/dt LoKv6b7vTHzUMvP5B2WCn/14vg9QVJRHb+Pz5re7tmjv+jL8oM+2Vk62uapeYmhW6bQO N+AQ== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=2pUBfclcaX6IoeI81431d6HNxDoUjpYgX+KHsvD40YA=; b=aBv9KBarnN1jc/8EK6pcMgjWVVUXx2OM978WQYOwNXGjGFX5CvT63Jg21VpAUKAAPo 2gauf7mMvvbMVZC+xVtNPcdWZOLeIvlabT76fS7bytU49Xa7r6PJm429VMl6KlDCZKtR b35WCqR6ZEJ74nqRU8BHo6G/Ul6ol/Xm1xpHfw3og3BQ8NehTsqRbVlU6QfFFGobSlph KJ0GPPMo77CKG4LkthHGtORJ5kJ8eJeNKEwr0WpAZWzeavx0VL3ujb8vq1XlHSCQLfDL OzEPWWAuuUVC4cgZPQ8bcoGDqNWJVsPvmYYLNIlZpImwP3DcitEoj4G0C5WVtHW+p5xL s5bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=r640hxXe; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g59-v6si25377516wrd.56.2018.06.07.16.48.28; Thu, 07 Jun 2018 16:48:28 -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=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=r640hxXe; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2CB768A89E; Fri, 8 Jun 2018 02:43:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9BB2768A86F for ; Fri, 8 Jun 2018 02:43:27 +0300 (EEST) Received: by mail-wm0-f42.google.com with SMTP id n5-v6so243907wmc.5 for ; Thu, 07 Jun 2018 16:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=UompPRAOqmUvzDlMCQ2GNotlHN7aIJy6J7LRXpEZ6kg=; b=r640hxXeVwPDHvJGq1y+CJ34twZ8m/RcRjPPanhYs/IqwbSBK2QusWvURlchVPV6mS 3RAl3COyOCi6dHRa3Pszk1EMs4YKm5KroGIrr304r4V8GsYgNg9UaHMr6X0X7F2yjKDy r/0mx4kiXrPrqaeUChVZseHDa+KQkbSgjpEeFQZG/P1+1riT2u6MEPz3lEld65HcKOLO UM5ARiVc2SbO6B5mikGINUuuKYHCC8FnvHCY5PLk+Zz1VsGTQdWkHV/dk2Tdx3KU07vz Hr/DWo/RYB6vGbByzvPWyyWVjvV8QDrP2dosvs5bBspfG58MG46Ej135z/aJcCuLzQ99 r+8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=UompPRAOqmUvzDlMCQ2GNotlHN7aIJy6J7LRXpEZ6kg=; b=T3R7m5EQLeVWAoKBDJJrDSkQhwGNS7JUu+qK0Cz9MXdlgcKiSptuIUuyreF3EYyp3q sDLrCMcP9gG38xpGqORj6IAiKTY9l7eQyh4IYdbou+8zgG2Fq62eSYWEpnvwd5t8wnj5 zJlVqFIHLEIbQpz6NG7EqidERxHV1k3c5YLZurhjiTCkS1lnRO+RKsVG9GBmzBPB4yix 5wlswPl5UQnhK25YB6DCu29pzIW9pY1+38EiupDgRkqjQpmVXTSOI4jfpLVHvU9lJAq+ PEBmbIo47Zxfw3/kEMvqh/YBchBMqcDlxrxhfWv3CDH/NhGN/KXhnHDkJ0fQ/dVhXrST ZEDg== X-Gm-Message-State: APt69E2SaCo2/AQSIinifUMWxi9Kqa8UecEWc1csXqjoexqH+ZHSjZ7a hicVE+naL8A4NylOphHf43vB7jKE X-Received: by 2002:a1c:7a06:: with SMTP id v6-v6mr2928172wmc.90.1528415054738; Thu, 07 Jun 2018 16:44:14 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id r2-v6sm18640545wrq.55.2018.06.07.16.44.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 16:44:14 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Jun 2018 00:43:30 +0100 Message-Id: <20180607234331.32139-36-sw@jkqxz.net> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180607234331.32139-1-sw@jkqxz.net> References: <20180607234331.32139-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH v2 35/36] vaapi_encode_h265: Set level based on stream if not set by user X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Sets the level based on the stream properties if it is not explicitly set by the user. Also add a tier option to set general_tier_flag, since that affects the level choice. --- doc/encoders.texi | 4 ++++ libavcodec/vaapi_encode_h265.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index ceddfdda64..d61a1cc4bc 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -2659,6 +2659,10 @@ Include recovery points where appropriate (@emph{recovery_point} messages). @item aud Include access unit delimiters in the stream (not included by default). +@item tier +Set @emph{general_tier_flag}. This may affect the level chosen for the stream +if it is not explicitly specified. + @end table @item mjpeg_vaapi diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 2cee19be68..100f8338d7 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -30,6 +30,7 @@ #include "avcodec.h" #include "cbs.h" #include "cbs_h265.h" +#include "h265_profile_level.h" #include "hevc.h" #include "hevc_sei.h" #include "internal.h" @@ -48,6 +49,7 @@ typedef struct VAAPIEncodeH265Context { int qp; int aud; int profile; + int tier; int level; int sei; @@ -315,7 +317,7 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) ptl->general_profile_space = 0; ptl->general_profile_space = 0; ptl->general_profile_idc = avctx->profile; - ptl->general_tier_flag = 0; + ptl->general_tier_flag = priv->tier; if (chroma_format == 1) { ptl->general_profile_compatibility_flag[1] = bit_depth == 8; @@ -340,7 +342,25 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) ptl->general_lower_bit_rate_constraint_flag = 1; - ptl->general_level_idc = avctx->level; + if (avctx->level != FF_LEVEL_UNKNOWN) { + ptl->general_level_idc = avctx->level; + } else { + const H265LevelDescriptor *level; + + level = ff_h265_guess_level(ptl, avctx->bit_rate, + ctx->surface_width, ctx->surface_height, + 1, 1, 1, (ctx->b_per_p > 0) + 1); + if (level) { + av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name); + ptl->general_level_idc = level->level_idc; + } else { + av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to " + "any normal level; using level 8.5.\n"); + ptl->general_level_idc = 255; + // The tier flag must be set in level 8.5. + ptl->general_tier_flag = 1; + } + } vps->vps_sub_layer_ordering_info_present_flag = 0; vps->vps_max_dec_pic_buffering_minus1[0] = (ctx->b_per_p > 0) + 1; @@ -1146,9 +1166,17 @@ static const AVOption vaapi_encode_h265_options[] = { { PROFILE("rext", FF_PROFILE_HEVC_REXT) }, #undef PROFILE + { "tier", "Set tier (general_tier_flag)", + OFFSET(tier), AV_OPT_TYPE_INT, + { .i64 = 0 }, 0, 1, FLAGS, "tier" }, + { "main", NULL, 0, AV_OPT_TYPE_CONST, + { .i64 = 0 }, 0, 0, FLAGS, "tier" }, + { "high", NULL, 0, AV_OPT_TYPE_CONST, + { .i64 = 1 }, 0, 0, FLAGS, "tier" }, + { "level", "Set level (general_level_idc)", OFFSET(level), AV_OPT_TYPE_INT, - { .i64 = 153 }, 0x00, 0xff, FLAGS, "level" }, + { .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" }, #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \ { .i64 = value }, 0, 0, FLAGS, "level"