From patchwork Wed Aug 2 05:57:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 4584 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp809877vsu; Tue, 1 Aug 2017 22:57:37 -0700 (PDT) X-Received: by 10.223.139.21 with SMTP id n21mr19109928wra.116.1501653457228; Tue, 01 Aug 2017 22:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501653457; cv=none; d=google.com; s=arc-20160816; b=lAUh34oSv5EavTCTmw/bdO5LT7kbYAAM7bLKAxtvNPS5OHPsoyHbHwwlR8DfjwXJO3 2IxYW0nuqpOsmE1Ef/ezfd8bpej0VFubJNi6ZyTqA+S9ck45XF85mUTpCJ0qCOX3KWno BZW9XctZt1hxZEvJ63RVu8diYfr0X+0a7wdOBeUrW2BNKYfyJM59hZeNy8EYo9dUuYsl DzQBIUTa7bqBnIvT0HwpBEI/S/v9ZbFkfq+6/6YMle8k3u6KqEjml7Q/U5BszWGeGUG1 vlMZdotTUopMe2XCe/DW4FfreeZJZaj+jQGLFzNN14JnoRTBnU6GqmYuZq9+A3Ddw4dX Os2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-disposition:content-language :mime-version:user-agent:date:message-id:from:to:dkim-signature :delivered-to:arc-authentication-results; bh=PIgDQuWE06dPoqBvH71fOOLqeGXzS+qI63pp0x23L7c=; b=JXD/TlOCbXor7he8lGWQ2jnJjDwVIGvWkxrR7i5qJrCb2fHlKHs1pgLxN6JrXbUoK8 QHs33paH2EUGDwkSqIBBU3wMh7QkURFUuXeK60Fa0B4VkpDvHgBs1zMUr8OhzvMB1knm /BhfkwA0TRMARqZ8sUK8jDEb+BuQBTh1LVMrhAN9SZ1WhA8pdi9rf6y+7zk+Nt9CnF/8 ZLMhCsAsmVGgs6yr5n8gySkq50BJ0tEKFmLpNuX+YV7BHliBnK6jsRfy17k7Ov67fXh9 0UF9ky2eI86s831iqbsoR5u2p00C9/HepeKHL1E4LCxmhvMOxFHwB8RGj2+WNGGkL6Oe cU2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=vFCzKz1j; 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 a8si27670610wra.377.2017.08.01.22.57.36; Tue, 01 Aug 2017 22:57:37 -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.b=vFCzKz1j; 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 C68A668A3B2; Wed, 2 Aug 2017 08:57:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f51.google.com (mail-pg0-f51.google.com [74.125.83.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C5C8B68A314 for ; Wed, 2 Aug 2017 08:57:24 +0300 (EEST) Received: by mail-pg0-f51.google.com with SMTP id y129so17144638pgy.4 for ; Tue, 01 Aug 2017 22:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=YP0NCIo5MIpYJvrEtKZpc/+ot+64dVii9sAlli1IwS4=; b=vFCzKz1jWoKjV5HhsRLAtc4MDb/Ie75j2BBypr7TDQm2mmKkkEXQGMLD675KsX2dX1 d1vQ/lYc0EkmNKiyIbpVtH8aEwiYmUopYAARk4+cYC8YUkFKlvTxUh0K5IvatdZ+xHiW fZyaLQIxzm710rY81S2IsiZdz4nkpgvAUPrIGtfFioOU8sKLlE5Yf+fSrffdhgq9e8kl VSF1dUjsKoCL65DaSqgfGhvX3PK5PbomKdvdMHDsQ89jGQnvqt9hmqXJVAS9MXQF7Niq A/gCGVWbtl5Vv+BWmbxG8KmIbnwuSUfLrwN36qZ7d1Rf0hbiXj//NXLXWHSk7e4LIe6x AKTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=YP0NCIo5MIpYJvrEtKZpc/+ot+64dVii9sAlli1IwS4=; b=l9FRhp6soc9V8PnyPOteBXW5Y2ZBdMkJDeBrqShTLdjofb2FoM9DDSoD9KQXlB5vYY 2dzW8dqJ2gZUVyL4HnAIPbukU7Hg3IdlF3EI6rAK/60ae4joaGGZgUnyibF981V2gAv9 LXhm2bYbTwwTY6pLkbhRJQP0dtBi1iLiMRS5HUTwBSTdSKCKu64clR6jRqDmuHjI0WUt tVMt1LxQ8MkWxpseJcNDosh1eHLdLRDCY+voNRSoh6+QV4Zmfa9YMCoGylF/tyQo7mFa bHVlbNwltwLCAaSeRcMFANAxCGmITU6GAV37VchkjU9t21XeSoda+LNSHU9nG8W+iu2t T37A== X-Gm-Message-State: AIVw113IE1RDkaHIE9o8vpY9bShLQfBcTufxvwT69zrqU1E7vsSyO9Fn IDVTQaxKr2Q1VQ== X-Received: by 10.84.168.132 with SMTP id f4mr23500032plb.170.1501653446465; Tue, 01 Aug 2017 22:57:26 -0700 (PDT) Received: from [10.67.68.50] ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id j30sm17415642pga.51.2017.08.01.22.57.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 22:57:25 -0700 (PDT) To: FFmpeg development discussions and patches , Mark Thompson From: Jun Zhao Message-ID: <85ff27d3-266e-975c-0b3e-beaca5481498@gmail.com> Date: Wed, 2 Aug 2017 13:57:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-US Content-Disposition: attachment; filename*0="0004-lavc-vaapi_encode_h265-respect-slices-option-in-h265.pa"; filename*1="tch" X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From 82eb7d1c3120081a7073cfb379802a28c769ae18 Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Tue, 1 Aug 2017 23:07:34 -0400 Subject: [PATCH V2 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 | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index cf6b9388d1..aa85331260 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -176,6 +176,10 @@ typedef struct VAAPIEncodeH265Context { unsigned int ctu_width; unsigned int ctu_height; + int slice_of_ctus; + int slice_mod_ctus; + int last_ctu_index; + int fixed_qp_idr; int fixed_qp_p; int fixed_qp_b; @@ -962,6 +966,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 max_slices; if (pic->type == PICTURE_TYPE_IDR) { av_assert0(pic->display_order == pic->encode_order); @@ -1024,7 +1029,22 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, av_assert0(0 && "invalid picture type"); } - pic->nb_slices = 1; + max_slices = 1; + if (ctx->max_slices) { + max_slices = FFMIN(priv->ctu_height, ctx->max_slices); + if (avctx->slices > max_slices) { + av_log(avctx, AV_LOG_WARNING, "The max slices number per frame " + "cannot more than %d.\n", max_slices); + } else { + max_slices = avctx->slices; + } + } + + pic->nb_slices = max_slices; + + priv->slice_of_ctus = (priv->ctu_width * priv->ctu_height) / pic->nb_slices; + priv->slice_mod_ctus = (priv->ctu_width * priv->ctu_height) % pic->nb_slices; + priv->last_ctu_index = 0; return 0; } @@ -1047,9 +1067,11 @@ 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 = priv->slice_of_ctus + (priv->slice_mod_ctus > 0 ? 1 : 0); + if (priv->slice_mod_ctus > 0) + priv->slice_mod_ctus--; + priv->last_ctu_index += vslice->num_ctu_in_slice; switch (pic->type) { case PICTURE_TYPE_IDR: @@ -1103,9 +1125,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; if (pic->type == PICTURE_TYPE_IDR) { // No reference pictures. @@ -1198,6 +1224,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 this VAAPI version.\n"); + return 0; }