From patchwork Thu Jun 7 23:43:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 9316 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp195379jad; Thu, 7 Jun 2018 16:48:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK2FLLgg0gBILylml6JaLm2YpKFNPUJNQOT/Np2AbdBtXbiUbBtxmM7yukAq8mDG2pE5jYg X-Received: by 2002:adf:ad8a:: with SMTP id w10-v6mr3460622wrc.83.1528415292021; Thu, 07 Jun 2018 16:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528415292; cv=none; d=google.com; s=arc-20160816; b=Mj1kA5VICIGhg8UZYGgB6TDPin44lUUKQjsMHW1Ku6KskehNwUbAbNe0NUTDwJy27D pWcQIzx0LKwpLjqXQqFEH+QwagHiyEj1ZwIIMyQLdVUJU3vraWmQxH6U+m7C+10bZi/4 NJ42RrnfvM9pwlpQvr7qGMx0o1IRo9VS1Ws7EyPbiJXzfe+KYavsv/YKWgiTrPYolJe8 KLk4QEmjuNKfXPqLjmpK25KKKzB38asoSOrz/xwKigi55vGt1DFtFNNguXoAhULZGy9o lShkdEUcJoxJtJai9mf38YrIZ0kgOX8BVlXgLqE74/xHIAS6/yszFlgerfdexvd89XO1 21Bw== 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=+piobJXW5FPiT50ZqHFlQsdnAmpob3f/RrRqyTgZbAc=; b=ngTqM8kD9hsUbWsmMLNg+YuCmxA08yAbZoziSxuBUkm6g+M2FpGzmuyS7mQ2v2nbeb 2ZWohpMVBOCRgSAOekCGg+lDjy13c+NJwehyjvryBKtB6S30nmdCv90Xr7lYwyebopGC DwQG5DQVaHMQT8KNizHYon48ZUxBv2k+1aVqyh/c3NnX7sMG9hOBuQXc5eYZFb/FjPiU raKU0Z1AadlFZuPJ9IB+s9oy5TpKsfP4FKPa+yd85/SvaP3mZb3ZkZzgjMXOVb9Cl3vb /7BtyLDD+PSp3jiavb9SlIg7ekfwycmE5KD+v7y76PFr3QsYYOcZ5tuOAqzlL5ER1Mst DoLw== 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=dMTuxXVA; 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 z30-v6si6245466wrz.226.2018.06.07.16.48.11; Thu, 07 Jun 2018 16:48:11 -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=dMTuxXVA; 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 79B3568A88B; Fri, 8 Jun 2018 02:43:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0F01668A87F for ; Fri, 8 Jun 2018 02:43:25 +0300 (EEST) Received: by mail-wm0-f49.google.com with SMTP id l15-v6so343775wmc.1 for ; Thu, 07 Jun 2018 16:44:13 -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=i7zkc9ExAL5+nipEuoeHg4Cbez6EzEKuUaun9ZVC3iQ=; b=dMTuxXVAhzfVGvBQDiOSGqrafi+MMFKVC5AvjA7vR+7MdGq5n4vMok+5nw3iiPRuTs ajUiRTrm84sCboNGOtiGmnk1ozL3+QP3c5v4UBIWJjkelz2xG1Yi4icG/hRUvVc0Z26w mSoNQoSEu1OPOMzkGfo5vtsi+tcornAWAWReXJL3QyStn+FK/oY4kOkqJ4NbXMTzRlql Ps9XdjUCZ0Z87V8vQ73DzWQFHD+yoI3OWvfYZAGkMZ/gPQYfFzhgf1em3JOW8Pv28bfv NHBi/tHw4WMNgdZXExaWLFJF/npN/Zoet5GcaLqXMjh91FuwZEyy/Io1m4QDj6+sS1H4 A/FQ== 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=i7zkc9ExAL5+nipEuoeHg4Cbez6EzEKuUaun9ZVC3iQ=; b=loP9SX1dDAOAqEnz7PLlbtq41cFx+3JZ1WUpHVE9IbkEENSbXjyEsDpz6kp4Fsbesm wpBed3aU6n4XR0YqEw3LkSktWJCsNw25kKOn4/OBM9BP0DMuAkohsM/NFPRRAINTMvrg uakG8ZFMu/zrh3Zz9le7uJZJ38QlfDTqacALkbjQY5q72M+rAyCyBjV82UQyPwWXrcj0 D/HiQFxy8Si3Wjz7yINeyoGZUnc4Qo+bIri1NrrEtWmR+zzqDgE1KxHnd1YW+FkSNbxZ D3DeqbXqHUYHWUS5b2UBJcJl80rpjCBO/SEBENZJOQcukeOM5JEGEimVLlAEeaM+bRsV LZKA== X-Gm-Message-State: APt69E34xHS4xPdMWJf5/q2Oh/Jb4mY6uuaT0OAscss++1XHWZQl+i5X 2t8/ddNKSYxoy+fSYyzxzVIWYLC0 X-Received: by 2002:a1c:630a:: with SMTP id x10-v6mr3193385wmb.93.1528415052907; Thu, 07 Jun 2018 16:44:12 -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.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 16:44:12 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Jun 2018 00:43:28 +0100 Message-Id: <20180607234331.32139-34-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 33/36] 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/Makefile | 2 +- libavcodec/vaapi_encode_h265.c | 71 +++++++++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 079f546918..71b800c09d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -371,7 +371,7 @@ OBJS-$(CONFIG_HEVC_QSV_DECODER) += qsvdec_h2645.o OBJS-$(CONFIG_HEVC_QSV_ENCODER) += qsvenc_hevc.o hevc_ps_enc.o \ hevc_data.o OBJS-$(CONFIG_HEVC_RKMPP_DECODER) += rkmppdec.o -OBJS-$(CONFIG_HEVC_VAAPI_ENCODER) += vaapi_encode_h265.o +OBJS-$(CONFIG_HEVC_VAAPI_ENCODER) += h265_profile_level.o vaapi_encode_h265.o OBJS-$(CONFIG_HEVC_V4L2M2M_DECODER) += v4l2_m2m_dec.o OBJS-$(CONFIG_HEVC_V4L2M2M_ENCODER) += v4l2_m2m_enc.o OBJS-$(CONFIG_HNM4_VIDEO_DECODER) += hnm4video.o diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 97bb9cef6c..2cee19be68 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,35 @@ 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_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 +382,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 +401,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 +1061,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 +1143,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)",