From patchwork Tue Jul 9 01:10:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13868 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 58EC7447C15 for ; Tue, 9 Jul 2019 04:18:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4147568AF76; Tue, 9 Jul 2019 04:18:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DB3F68AF72 for ; Tue, 9 Jul 2019 04:18:14 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id v15so1325290wml.0 for ; Mon, 08 Jul 2019 18:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6tEadBBcae5Q/NDqW0BAR4VX5asxA4GmXTk93bZ8+Wc=; b=PfbmTbgfkAggTCC6FqEpwzbg5UBNvqV47Q4Y1sUOo6YjTsXnk+z0MH+CmHMpVPCNA+ NU60bvCYjf2wiBw5PxDvt9oXpvuQV4h1dS7eBtoFZpBjP8BzogYyBEWyxmZI0jws5guX kk5LuqJUgx7W/6qa8YIZWbQQEpqMX4b1t0EtmUu+JdlRXc0xPTV8pi1NDKlWPompwagD hEWYvNmbX0vAR/JrVUf3T2yD0zFDvyhB2j4eYB0thKyrRTMgAgeALr9GjeAGs5tr5BCP bh5zIQUmAtogikeRNswEibgDsl+BWtseKr1JvbI8lFLrZzqAUjr3OYjLCrr7kNRoJeCh 15rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6tEadBBcae5Q/NDqW0BAR4VX5asxA4GmXTk93bZ8+Wc=; b=knJqZOOL9AgQiGzGl7PKOPiT4ZqtPjOApFre0UCeAwzUitemLEAN+h+ODioUAltnLI BzlWsfi+I8U9LrL4y+FaupZ0iOxjCIwORQggHlfYmsRgbivnnv23CDv2hYpVn2SVQnil ms2fe/lGJzrGFJuTirJzKKWQwn3nOhkVX2XYwQE4+wmBzoUYXHMj+G/om9dWL14eUNDn +iR33cCeyqigCtazk8gunrif6yObo9ZP0wlMaKGh2nudhbFeUMYxyYrdhFo5Jp/trnBI ixBPvbfhh/HCrOe+ISlsGl4Tox8RzdfJC0zDWG4Q9f9OdnYdJjCEUsEKHb3Avc+r7x54 GIAw== X-Gm-Message-State: APjAAAUqoO5pde9mtmJLSEqnFulHiaCszr7/pPVvASPTRfb3iBql1VjW ogRB1zdE7evjPyzhg34pYel7WjiF X-Google-Smtp-Source: APXvYqy+13UGeYSwNlocZNLxzXxmHrNw1+yoQ/DSTT5TBkuoHD4IYleUCjEqVM+zmnR2bNR8g/KqXQ== X-Received: by 2002:a05:600c:225a:: with SMTP id a26mr19765361wmm.81.1562634702774; Mon, 08 Jul 2019 18:11:42 -0700 (PDT) Received: from localhost.localdomain (ipbcc08b8f.dynamic.kabel-deutschland.de. [188.192.139.143]) by smtp.gmail.com with ESMTPSA id a84sm1140319wmf.29.2019.07.08.18.11.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 18:11:42 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Jul 2019 03:10:48 +0200 Message-Id: <20190709011048.29601-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709011048.29601-1-andreas.rheinhardt@gmail.com> References: <7166cd5e-8604-3842-3191-e0d47d7ac934@gmail.com> <20190709011048.29601-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 31/31] hevc_metadata: Update AVCodecParameters during init 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit makes hevc_metadata update the AVCodecParameters during init to bring them in line with the changes to the bitstream. Notice that for field-based HEVC the derived height is the height of a frame, which deviates from current FFmpeg behaviour. Signed-off-by: Andreas Rheinhardt --- I am unsure about the part about the height of field-based HEVC. libavcodec/h265_metadata_bsf.c | 37 ++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c index b3a1fda144..01a955028b 100644 --- a/libavcodec/h265_metadata_bsf.c +++ b/libavcodec/h265_metadata_bsf.c @@ -193,8 +193,8 @@ static int h265_metadata_update_vps(AVBSFContext *bsf, return 0; } -static int h265_metadata_update_sps(AVBSFContext *bsf, - H265RawSPS *sps) +static int h265_metadata_update_sps(AVBSFContext *bsf, H265RawSPS *sps, + int *width, int *height) { H265MetadataContext *ctx = bsf->priv_data; int need_vui = 0; @@ -328,6 +328,13 @@ static int h265_metadata_update_sps(AVBSFContext *bsf, CROP(bottom, crop_unit_y); #undef CROP + if (width && height) { + *width = sps->pic_width_in_luma_samples - crop_unit_x * + (sps->conf_win_left_offset + sps->conf_win_right_offset); + *height = (1 + sps->vui.field_seq_flag) * (sps->pic_height_in_luma_samples + - crop_unit_y * (sps->conf_win_top_offset + sps->conf_win_bottom_offset)); + } + if (need_vui) sps->vui_parameters_present_flag = 1; @@ -412,7 +419,8 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) goto fail; } if (au->units[i].type == HEVC_NAL_SPS) { - err = h265_metadata_update_sps(bsf, au->units[i].content); + err = h265_metadata_update_sps(bsf, au->units[i].content, + NULL, NULL); if (err < 0) goto fail; } @@ -438,7 +446,9 @@ static int h265_metadata_init(AVBSFContext *bsf) { H265MetadataContext *ctx = bsf->priv_data; CodedBitstreamFragment *au = &ctx->access_unit; - int err, i; + int err, i, width = -1, height = -1, level = ctx->level; + int color_range = ctx->video_full_range_flag; + int chroma_location = ctx->chroma_sample_loc_type; err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_HEVC, bsf); if (err < 0) @@ -451,8 +461,10 @@ static int h265_metadata_init(AVBSFContext *bsf) goto fail; } - if (ctx->level == LEVEL_AUTO) + if (ctx->level == LEVEL_AUTO) { h265_metadata_guess_level(bsf, au); + level = ctx->level_guess ? ctx->level_guess : level; + } for (i = 0; i < au->nb_units; i++) { if (au->units[i].type == HEVC_NAL_VPS) { @@ -461,7 +473,8 @@ static int h265_metadata_init(AVBSFContext *bsf) goto fail; } if (au->units[i].type == HEVC_NAL_SPS) { - err = h265_metadata_update_sps(bsf, au->units[i].content); + err = h265_metadata_update_sps(bsf, au->units[i].content, + &width, &height); if (err < 0) goto fail; } @@ -474,6 +487,18 @@ static int h265_metadata_init(AVBSFContext *bsf) } } + if (color_range >= 0) + color_range++; + if (chroma_location >= 0) + chroma_location++; + + ff_cbs_update_video_parameters(ctx->cbc, bsf->par_out, -1, level, + width, height, -1, color_range, + ctx->colour_primaries, + ctx->transfer_characteristics, + ctx->matrix_coefficients, + chroma_location, -1); + err = 0; fail: ff_cbs_fragment_reset(ctx->cbc, au);