From patchwork Wed Aug 23 11:12:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 4806 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.137.29 with SMTP id o29csp1848426jaj; Wed, 23 Aug 2017 04:20:31 -0700 (PDT) X-Received: by 10.223.129.35 with SMTP id 32mr1630360wrm.23.1503487231881; Wed, 23 Aug 2017 04:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503487231; cv=none; d=google.com; s=arc-20160816; b=V6MObcAeZepQ9yb/b2p/ipSRKjXMx87MfJerEoV1o5ljyTeq5oCPHR3B0kU9yjvS4L 4gue+pmmUrU0/UzsR0vw/NGgQLb2CeTOorgf0UcXpSRQvIL33OJpJ6HYM2jz+6oi8WED C7WFfJLGG0obA+GVbn20Sh4uBfOxvyZsISS3GB6qkSOWrDvuzHFPFw4MmPEz3YwaXqxV qgqpBnMh301okbq8thgBev5DW/LJejjU4ZbWYWVfR5vu8To4oAhoqNlr01mceSojdNnv FjGEpFf3lOK3HS9Y+EHRikRwVLJDDZEzOlxeMVCUGdLH97vlkIXlxIYi/7v2lNku6hlp E/qw== 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:to:message-id:date:from:references :in-reply-to:mime-version:dkim-signature:delivered-to :arc-authentication-results; bh=a+cZaDa0ahHlwmTWcTFXbOuERc2TlbSOZ2YnZz8YHaM=; b=hW/fNHnWJDoPMGZjlnUsVg04DPveVsRj5k2NcD7BWxQSX4vXVeSBzX7Y1iLxCqFVID la3Df3rl74XINaLq5n7qrtXRnitC2QmjbvFPwNIGB/bUsbQjJ3krmig737keRsXWeSlO +ycBsMdCIoYIBvN0ZRSk/g3na7sOvxF4s5oK4aqSqfz0jeBORcLieuTVnx1l9k1/GyHu CksdQrS7ooEXyS8o8jwdxfijEpi75Kz3Rpcg6uvbWdE4bdrMdG9QUWtMYD0t/th7Q3QS XIDeDtZqaLXNuMcd8JfGBU83y2Afn/f39M6ciXYnAJ1A2L4yoryBz7VgCXHulmXYvmo0 1xwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=K0unEwto; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t44si1190813wrc.532.2017.08.23.04.20.29; Wed, 23 Aug 2017 04:20: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=@gmail.com header.s=20161025 header.b=K0unEwto; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CF64F689DE4; Wed, 23 Aug 2017 14:20:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi0-f66.google.com (mail-oi0-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 46974689D75 for ; Wed, 23 Aug 2017 14:20:14 +0300 (EEST) Received: by mail-oi0-f66.google.com with SMTP id j144so1307639oib.5 for ; Wed, 23 Aug 2017 04:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=gr5giUNhhzDSdoP2uebEyk8s07zxPFhm7xNyCxIv1Og=; b=K0unEwtooKV3dGF6hYD4ORIQQ1wl+rmgwKCmm6Hc6SGRPLX+blNanzTKhGlLH6Z7cD j0L2t5nGAcJL0ZGOdZDs1za8H7QVcRmi66QrcGJ5LVsRcZZZtwKKwJiShH8KUIe/4gTp h9km84dck2raOzaTjMfiUswj4tWlqpzrZAAI68mmxpLb8aotPSq/PGzNah+CyfTx7Zmu fDExJRfHXqls4VAXNPvPVuEIR6ZcJEox+euord72ITQai8HHPGx1d71DrHeeab8KvZII 1DBNH35WvK/k5A+8PjX/D/Jkx1XeXBEK2BD47aD+BdQffuGT8oxWPZjsE0Vxf+bB7jIu 5Lkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=gr5giUNhhzDSdoP2uebEyk8s07zxPFhm7xNyCxIv1Og=; b=UUgHYS462Kx6r70q795WVwFDVriKOTmk7WyWuBWWHlG9kbCXvC6jCwLn9KbHkQzLye Jw72MQQkaoEFE5nliJtOzMKRN1tEoGQRnZxKwKXoXfsTUdg7iEUwtasZ9+2S4/4BP585 YsCa1Spdd1GIP6YF/j7vmorcyaLNA25kX3zTWHmWjmniarXgqZKiXz6SC6fEt+dlDTml OF3LTLZc/IBsGe+cOq/8VnYnVBbzSh8QwxmzRbUJZbesNRneRfIX8oUScxIAgpZ3BzwE 4LDINo9k4OrdF6N1v2lCfphty/XRwfOiiojlS0hbSydWn+P/ABTDazgmUpO7fOho49R2 /qzg== X-Gm-Message-State: AHYfb5j3eeeEvmMrQCDElxfUJQqDddjuHFv+mXpVMiSwmN+ipKifFEmy EX6IxtSnQSB5HLVVRhHwVwPap0GkrcWO X-Received: by 10.202.86.137 with SMTP id k131mr2599852oib.213.1503486748841; Wed, 23 Aug 2017 04:12:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.46.20 with HTTP; Wed, 23 Aug 2017 04:12:28 -0700 (PDT) In-Reply-To: References: From: Steven Liu Date: Wed, 23 Aug 2017 19:12:28 +0800 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH V4 4/4] lavc/vaapi_encode_h265: respect "slices" option in h265 vaapi encoder 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 Cc: Mark Thompson Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 2017-08-23 18:34 GMT+08:00 Jun Zhao : > >From dae9051c0828f7c86417308d06f1deb0640534bc Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Tue, 1 Aug 2017 23:07:34 -0400 Subject: [PATCH V4 4/4] lavc/vaapi_encode_h265: respect "slices" option in h265 vaapi encoder Enable multi-slice support in AVC/H.265 vaapi encoder. Signed-off-by: Wang, Yi A Signed-off-by: Jun Zhao --- libavcodec/vaapi_encode_h265.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) av_assert0(pic->display_order == pic->encode_order); @@ -1024,7 +1027,19 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, av_assert0(0 && "invalid picture type"); } - pic->nb_slices = 1; + slices = 1; + if (ctx->max_slices) { + if (avctx->slices <= ctx->max_slices) { + slices = avctx->slices; + } else { + slices = avctx->slices; What about move this "slices = avctx->slices;" out of the conditional ? + av_log(avctx, AV_LOG_WARNING, "The max slices number per frame " + "cannot more than %d.\n", slices); + } + } + pic->nb_slices = slices; + + priv->last_ctu_index = 0; return 0; } @@ -1047,9 +1062,10 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, pslice = slice->priv_data; mslice = &pslice->misc_slice_params; - // Currently we only support one slice per frame. - vslice->slice_segment_address = 0; - vslice->num_ctu_in_slice = priv->ctu_width * priv->ctu_height; + vslice->slice_segment_address = priv->last_ctu_index; + vslice->num_ctu_in_slice = + ((slice->index + 1) * priv->ctu_width * priv->ctu_height) / pic->nb_slices - priv->last_ctu_index; + priv->last_ctu_index += vslice->num_ctu_in_slice; switch (pic->type) { case PICTURE_TYPE_IDR: @@ -1103,9 +1119,13 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, else vslice->slice_qp_delta = priv->fixed_qp_idr - vpic->pic_init_qp; - vslice->slice_fields.bits.last_slice_of_pic_flag = 1; + if (priv->last_ctu_index == priv->ctu_width * priv->ctu_height) + vslice->slice_fields.bits.last_slice_of_pic_flag = 1; - mslice->first_slice_segment_in_pic_flag = 1; + if (vslice->slice_segment_address == 0) + mslice->first_slice_segment_in_pic_flag = 1; + else + mslice->first_slice_segment_in_pic_flag = 0; What about: mslice->first_slice_segment_in_pic_flag = vslice->slice_segment_address ? 0 : 1; ? if (pic->type == PICTURE_TYPE_IDR) { // No reference pictures. @@ -1198,6 +1218,10 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx) av_assert0(0 && "Invalid RC mode."); } + if (!ctx->max_slices && avctx->slices > 0) + av_log(avctx, AV_LOG_WARNING, "The encode slice option is not " + "supported with the driver.\n"); + return 0; } diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index cf6b9388d1..e27b554a98 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -176,6 +176,8 @@ typedef struct VAAPIEncodeH265Context { unsigned int ctu_width; unsigned int ctu_height; + int last_ctu_index; + int fixed_qp_idr; int fixed_qp_p; int fixed_qp_b; @@ -962,6 +964,7 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params; VAAPIEncodeH265Context *priv = ctx->priv_data; int i; + int slices; if (pic->type == PICTURE_TYPE_IDR) {