From patchwork Thu Jun 7 23:43:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 9309 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp194906jad; Thu, 7 Jun 2018 16:47:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJfABnZikQ8ARiqpK7VdpBqEFqUJ8MUX1ZAjITqeh+fyUDUEUmAmglpPwQjSXdUczuz8Ae+ X-Received: by 2002:a1c:448b:: with SMTP id r133-v6mr2709724wma.55.1528415251958; Thu, 07 Jun 2018 16:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528415251; cv=none; d=google.com; s=arc-20160816; b=07uCI6S+IZV86ojcAC5f4bmOt4tWoIIDg+acAueJ57SjviQF59+1MoJhCzz4hN7bQj mnIYejTaqitoPTa87mVhj4a+VWlKh+j1lo3oK1wygu3TRKOECst35Eibj/V89mBKsqke Qm8suQneUDu/fL4IUyTYg2d+2+atYZI9dcaLQ5dpuWjaXTdrIg17NE16Tj4b/F/EGHTB UReDaEcOfFw2YIJ4lt8VF6nneMtH0mWX1BTnoWQV80GKWx5YLlRmBsqEifSpcwx0aO6+ dnkRjn846nhabelWG6V+o5XcN8uzQHCtfw2HSfWhquPjbwX1LtPJZGdLo1HT1VkKXXGh ehJg== 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=TKPs8emPJIwFhraBctjRfd9X38/QVvW3s3siWS68T9I=; b=wo5UjbKoO0FzrrZELsqKccUDik8afPRuT2JBhokSyjhLMAkIkRbCS+PC+e9Hk9NbUy YPinduBPZ71cU7bBCLDKtR+u2aDIoX/yDizUr4PXWgPNFxpetArpFp4/PF60cJDG6fY7 dm+GlJ+7+sf7QIsuGY9RLTosoDTmHeUhKNsoa2gZt7xMlxQDqVVWOTWlhst/f0mRad/O UbA+4uULdh23it5PWnK1S5ILfqDLZ1hi31TKD83JaIm21nICljN8HpH/HlXqKejAqhl8 q4Zdq5oGsUd3O0iiKFsLIJZA1mvHZ7Gv6BNgp1NY5l2BNsg6Nw2pL2Q21Q03rct0QX+K OlJA== 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=hAHwxXzr; 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 z72-v6si33062374wrb.448.2018.06.07.16.47.31; Thu, 07 Jun 2018 16:47:31 -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=hAHwxXzr; 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 847CB68A858; Fri, 8 Jun 2018 02:43:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f171.google.com (mail-wr0-f171.google.com [209.85.128.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0CA2B68A832 for ; Fri, 8 Jun 2018 02:43:20 +0300 (EEST) Received: by mail-wr0-f171.google.com with SMTP id d8-v6so11536105wro.4 for ; Thu, 07 Jun 2018 16:44:08 -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=jGhpLd2BhsFkbkjcFAMlUTOcO8MqIuCZdfkhTrFKclU=; b=hAHwxXzrtzfTgpHyTa18YD5N1XS8KWrNoMKjApKvsTbSW5qbxbkrQmHNW7fLcH8a1M ZwEwP0zZLeubo9ac+jKda9FNXnSs1i7jJoQX+CPHBcVJEkVJEdOBEgFJmCxsauZuZI2P GhNnDVs2o4YXiLjKsnWQe98I/xQeSKqXawAQmWuPswaR8nx27qiEeU7TTLbhQLidMNQN M23xAgPUJW/FORy3fNVPcA6sUgTy2ue8ZeezRj3/13PUF3hi53AR8sZR91qERw7nn363 hG+TQFPxOUm++5N07ceRXp/ImYlbNtixBb0rz6ahC6uz4B0V3KgbnRUktZvtYII3F2rt aF0A== 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=jGhpLd2BhsFkbkjcFAMlUTOcO8MqIuCZdfkhTrFKclU=; b=U35EfrSaNcoNNVlaXhn2ESl2ShkhxMB5iczIAYn0onBw0yFGaQpwoK1eqMx71S1QnB 1suCBVWtSYkCHvPIWPuxzzmqR7f1QtYruwia7wYAMWQaM8qRnOMOAU0vG83bXB/lSuof 0+fBgXkWtSGz4tAhHgCbWmx40KUhlxU8SFgTzrSQKgiIZGO0LhhBBVL0elo/uOoRCg4L iCTmaUknRvSzTCx1P8t/W4v3/BghjvGNBN4FN04DAhV+mnkY7tH+L6U3om79caz/XDn/ WzFgHw1AHM6/yp8+9G7Zn4Lyt55ATNvDIck6W8myFEczTNZnt886nI2K9lFyydD16p64 5/Mw== X-Gm-Message-State: APt69E0LMDnGpr4l+0ryZwJz53ZFVJUrPFgce3FVHCEsPiljzqI9i9Q5 I96Ss3gAt1Az0NRXuG/jQJKxqGjj X-Received: by 2002:adf:b2c9:: with SMTP id g67-v6mr3339793wrd.147.1528415047928; Thu, 07 Jun 2018 16:44:07 -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.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 16:44:07 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Jun 2018 00:43:23 +0100 Message-Id: <20180607234331.32139-29-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 28/36] vaapi_encode_h264: 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" --- libavcodec/vaapi_encode_h264.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index 82166d4457..4034053dc0 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -30,6 +30,7 @@ #include "cbs.h" #include "cbs_h264.h" #include "h264.h" +#include "h264_levels.h" #include "h264_sei.h" #include "internal.h" #include "vaapi_encode.h" @@ -294,6 +295,7 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) H264RawPPS *pps = &priv->raw_pps; VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params; + int dpb_frames; memset(&priv->current_access_unit, 0, sizeof(priv->current_access_unit)); @@ -319,7 +321,32 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) sps->constraint_set5_flag = ctx->b_per_p == 0; } - sps->level_idc = avctx->level; + if (ctx->gop_size == 1) + dpb_frames = 0; + else + dpb_frames = 1 + (ctx->b_per_p > 0); + + if (avctx->level != FF_LEVEL_UNKNOWN) { + sps->level_idc = avctx->level; + } else { + const H264LevelDescriptor *level; + + level = ff_h264_guess_level(sps->profile_idc, + avctx->bit_rate, + priv->mb_width * 16, + priv->mb_height * 16, + dpb_frames); + if (level) { + av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name); + if (level->constraint_set3_flag) + sps->constraint_set3_flag = 1; + sps->level_idc = level->level_idc; + } else { + av_log(avctx, AV_LOG_WARNING, "Stream will not conform " + "to any level: using level 6.2.\n"); + sps->level_idc = 62; + } + } sps->seq_parameter_set_id = 0; sps->chroma_format_idc = 1; @@ -329,8 +356,7 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) sps->log2_max_pic_order_cnt_lsb_minus4 = av_clip(av_log2(ctx->b_per_p + 1) - 2, 0, 12); - sps->max_num_ref_frames = - ctx->gop_size == 1 ? 0 : 1 + (ctx->b_per_p > 0); + sps->max_num_ref_frames = dpb_frames; sps->pic_width_in_mbs_minus1 = priv->mb_width - 1; sps->pic_height_in_map_units_minus1 = priv->mb_height - 1; @@ -1005,7 +1031,7 @@ static const AVOption vaapi_encode_h264_options[] = { { "level", "Set level (level_idc)", OFFSET(level), AV_OPT_TYPE_INT, - { .i64 = 51 }, 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"