From patchwork Tue Sep 18 22:31:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 10384 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp13653jap; Tue, 18 Sep 2018 15:35:08 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYchwOE0mF4vFxxHtvp0L+l9m9RfgsprZMn4MZWn0xl8noNhV63iod8n4Xk2kj228exmVow X-Received: by 2002:adf:8024:: with SMTP id 33-v6mr25206363wrk.16.1537310108145; Tue, 18 Sep 2018 15:35:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537310108; cv=none; d=google.com; s=arc-20160816; b=nY3ru8qzKPi0rah7VibFPZrGtr4rk4xGacwwGOG+PyCct/hWezmGiQK8yzkNvL9Eou mgY8d+XReK6kkoL3v8ediwzIRY4yIYzysftbGz2WIGnTLO7nrKEuGhtAZHXnboJz6ZL/ bryFEvA5PMDHNwLREEj+lWzaTlh2yyKDIzQhbe0yAzuLgPK6bGoPXwSAjHrH/Lnse15q MLJgi+9j0rYg0tTKu5h5cYzbgKVFBC339HL0JxvoSfpQmphfayR/fotH+Z/rJwcybyDP YJcv/CvVJ4fKinpSqgTA/kWSxcPntZ+nA8pMNNJKPh87NhCe8HgKD+B4RPAPbVSUWjUB poOA== 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; bh=YjN8/PSH0tob87MNPLUThTFDBWScbDYDlFS/cdbNJfk=; b=ur92XOrwRZ1s/y/9ActrzFH1nHciSYTd9LtbDxjXHIfx1nRKcPRe0+2kQq0Qo7dRcO UDrkC+a48jvwI0J+ef55eRFzGqS5it3dZFAbSwfnv9QGnkhclCiVTtHOwplBABB3fT7d boP8W2dmreCKOqFq0wZChmjrsCONNB7W8xwqbXUB3bAbGIY9xptSocXK9uY0QOidJwck 8Hh1K9Q503yVMD+yaKrOVx78hyz28Ec20ct8vkgqr4j0wVlH28Ps7j3oWxIPzn/2bUv8 oAIwVaGQI+NdZBsJrFdqwnHnCVIgWo91O1FTfjlweV9xXoh8RQLSYX17itNLj2lhCrpQ FsRA== 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=mEukS5R+; 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 s7-v6si3379884wro.199.2018.09.18.15.35.07; Tue, 18 Sep 2018 15:35:08 -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=mEukS5R+; 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 35D6668A632; Wed, 19 Sep 2018 01:31:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B91868A613 for ; Wed, 19 Sep 2018 01:31:35 +0300 (EEST) Received: by mail-wr1-f44.google.com with SMTP id e1-v6so3742589wrt.3 for ; Tue, 18 Sep 2018 15:31:48 -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=nYqjF4cCcPGpLQFmPcu0xPquvWOqFMS9/+y2VENjFG8=; b=mEukS5R+Hb5DagGIVk/To1+oGqZ+rr6jO99/qkCVPBBJmTlay2QgYm/3C3FgWUdsBu qM8Tmm14oQNTdEK1pi9ekhcJI6PKsujubRwBPpB7Jf0zNumAtxrc4SxXt/Gb3w8PfQ3R lUhdcIPpzUDPoygoh5zmhp2MAbl6Wh+Ne+hZV73Q4jAZ4c0yGvi/e/HUBrlXIvFYwU+X G/ZKpFD/x6NiiVOmaEWxdzNbFPlvS7nGzfsndSH25ZSczH0SplaXt3OlHuNoqgTpj2Eg J1Nxac0wiWPD3l8HiXtxFQX/3tP6Go6ZyVlypHlVZlVFPfRAXHduqvVdIk/cv/+Nblz8 qnBQ== 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=nYqjF4cCcPGpLQFmPcu0xPquvWOqFMS9/+y2VENjFG8=; b=rqoRGbsfddfuYCzFEb6iQx7PaANGEYPvMG4luzzZwfJhoOYvH2WLvvEveiCqLcQ9IT xtslI3uPCDsLKg8S14VoRd1a4JhGdG/OkZ4iUF95BHF/xIrEloutcuuKCBBnCoyykF+Z vcP+eNmnULNjn66TQ3sNmqMxbDG2ymxdo1sKne0Wu1HYinz4OLsSukG3g/Baw+mDTxvC hSaNmsPG13d7qyzz8OkRgxQcgQfrAquA4S7SOQbRzHrom1/EZfOeG0mvewwysslTgF9p CezfXuc/iy9SSdl4DUs8Q8Vbbbji3Oq24t76EQzb9DNgmQtXXQCeN5A5YRxsOcpy9LB3 xtWw== X-Gm-Message-State: APzg51DfacvFTzcePuaCWJZ78VTBeYbDSlZ+k8LUQVpmlhwoLTBZTKEf kBWPQoJAFzL1n8bje/H9r1Ct+O7MbrY= X-Received: by 2002:a5d:5088:: with SMTP id a8-v6mr4846125wrt.37.1537309907649; Tue, 18 Sep 2018 15:31:47 -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 e141-v6sm4863826wmd.32.2018.09.18.15.31.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 15:31:46 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Sep 2018 23:31:03 +0100 Message-Id: <20180918223116.14322-26-sw@jkqxz.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180918223116.14322-1-sw@jkqxz.net> References: <20180918223116.14322-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH v4 25/38] vaapi_encode_h265: Improve profile support 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" Set profile compatibility/constraint flags properly (including the constraint flags used for RExt profiles, as all streams we can currently generate are RExt-compatible), and use that to add support for the "Main Intra" and "Main 10 Intra" RExt subprofiles (for which we can re-use the existing Main and Main10 VAAPI profiles). --- libavcodec/vaapi_encode_h265.c | 70 ++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 6940a59240..45576868df 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -23,6 +23,7 @@ #include "libavutil/avassert.h" #include "libavutil/common.h" +#include "libavutil/pixdesc.h" #include "libavutil/opt.h" #include "libavutil/mastering_display_metadata.h" @@ -260,9 +261,12 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) H265RawVPS *vps = &priv->raw_vps; H265RawSPS *sps = &priv->raw_sps; H265RawPPS *pps = &priv->raw_pps; + H265RawProfileTierLevel *ptl = &vps->profile_tier_level; H265RawVUI *vui = &sps->vui; VAEncSequenceParameterBufferHEVC *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferHEVC *vpic = ctx->codec_picture_params; + const AVPixFmtDescriptor *desc; + int chroma_format, bit_depth; int i; memset(&priv->current_access_unit, 0, @@ -273,6 +277,25 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) memset(pps, 0, sizeof(*pps)); + desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format); + av_assert0(desc); + if (desc->nb_components == 1) { + chroma_format = 0; + } else { + if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1) { + chroma_format = 1; + } else if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 0) { + chroma_format = 2; + } else if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) { + chroma_format = 3; + } else { + av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format " + "%s is not supported.\n", desc->name); + } + } + bit_depth = desc->comp[0].depth; + + // VPS vps->nal_unit_header = (H265RawNALUnitHeader) { @@ -289,19 +312,34 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) vps->vps_max_sub_layers_minus1 = 0; vps->vps_temporal_id_nesting_flag = 1; - vps->profile_tier_level = (H265RawProfileTierLevel) { - .general_profile_space = 0, - .general_profile_idc = avctx->profile, - .general_tier_flag = 0, + ptl->general_profile_space = 0; + ptl->general_profile_idc = avctx->profile; + ptl->general_tier_flag = 0; - .general_progressive_source_flag = 1, - .general_interlaced_source_flag = 0, - .general_non_packed_constraint_flag = 1, - .general_frame_only_constraint_flag = 1, + if (chroma_format == 1) { + ptl->general_profile_compatibility_flag[1] = bit_depth == 8; + ptl->general_profile_compatibility_flag[2] = bit_depth <= 10; + } + ptl->general_profile_compatibility_flag[4] = 1; - .general_level_idc = avctx->level, - }; - vps->profile_tier_level.general_profile_compatibility_flag[avctx->profile & 31] = 1; + ptl->general_progressive_source_flag = 1; + ptl->general_interlaced_source_flag = 0; + ptl->general_non_packed_constraint_flag = 1; + ptl->general_frame_only_constraint_flag = 1; + + ptl->general_max_12bit_constraint_flag = bit_depth <= 12; + ptl->general_max_10bit_constraint_flag = bit_depth <= 10; + ptl->general_max_8bit_constraint_flag = bit_depth == 8; + + ptl->general_max_422chroma_constraint_flag = chroma_format <= 2; + ptl->general_max_420chroma_constraint_flag = chroma_format <= 1; + ptl->general_max_monochrome_constraint_flag = chroma_format == 0; + + ptl->general_intra_constraint_flag = ctx->gop_size == 1; + + ptl->general_lower_bit_rate_constraint_flag = 1; + + ptl->general_level_idc = avctx->level; vps->vps_sub_layer_ordering_info_present_flag = 0; vps->vps_max_dec_pic_buffering_minus1[0] = (ctx->b_per_p > 0) + 1; @@ -343,7 +381,7 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) sps->sps_seq_parameter_set_id = 0; - sps->chroma_format_idc = 1; // YUV 4:2:0. + sps->chroma_format_idc = chroma_format; sps->separate_colour_plane_flag = 0; sps->pic_width_in_luma_samples = ctx->surface_width; @@ -362,9 +400,8 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) sps->conformance_window_flag = 0; } - sps->bit_depth_luma_minus8 = - avctx->profile == FF_PROFILE_HEVC_MAIN_10 ? 2 : 0; - sps->bit_depth_chroma_minus8 = sps->bit_depth_luma_minus8; + sps->bit_depth_luma_minus8 = bit_depth - 8; + sps->bit_depth_chroma_minus8 = bit_depth - 8; sps->log2_max_pic_order_cnt_lsb_minus4 = 8; @@ -1023,8 +1060,10 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx) static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = { { FF_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain }, + { FF_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain }, #if VA_CHECK_VERSION(0, 37, 0) { FF_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 }, + { FF_PROFILE_HEVC_REXT, 10, 3, 1, 1, VAProfileHEVCMain10 }, #endif { FF_PROFILE_UNKNOWN } }; @@ -1103,6 +1142,7 @@ static const AVOption vaapi_encode_h265_options[] = { { .i64 = value }, 0, 0, FLAGS, "profile" { PROFILE("main", FF_PROFILE_HEVC_MAIN) }, { PROFILE("main10", FF_PROFILE_HEVC_MAIN_10) }, + { PROFILE("rext", FF_PROFILE_HEVC_REXT) }, #undef PROFILE { "level", "Set level (general_level_idc)",