From patchwork Tue Jul 9 01:10:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13865 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 39C3A44758E for ; Tue, 9 Jul 2019 04:11:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 292E868AF61; Tue, 9 Jul 2019 04:11:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 926B768AF28 for ; Tue, 9 Jul 2019 04:11:42 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id n4so19117616wrs.3 for ; Mon, 08 Jul 2019 18:11:42 -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=zJwCQ8PTeZfpKUydjH+AcOV69L7oBTpyV5sKPWrQfDY=; b=Ug6jcFe3ojM6d8rx5hOaIx1Y95e2qiB+O4xYLxXAZaztJ+O0pOrLP4PAuVWxa3D69F 6TXVFxouRdBfzjAXNTgN19YbR1E/OCeac+rd0b23SbyFyE8JRsNpgnr9kFbqy+D/fzLH Hhxp7Mr4UmANVxkhhGIgTarL5Z67yzT31i8mFoG5y7IRaJUjQszoDVPA0veeFlfXKs6J v41x1hofyRIldCCgJ5WliU9weOoU8ozOW6DKTgW1LS3tFu1QQc8ccZoa6Ap6GObZppUx IRRjkaYHJLI0BM9pnPo6Jk/qO76oUxCv4RqU2JOf1OXSu68eGgma0TbZeWT7PEziOt8P +wsg== 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=zJwCQ8PTeZfpKUydjH+AcOV69L7oBTpyV5sKPWrQfDY=; b=hvAleCLvczcvPalr90nd3RMBeWEQitctXPdfV5Wyu8TEF4R7rJSSHKcJb7uENYBXCW NhE4s06U3C6znYLazJNN2BRYzXthhhGy83D16udiImofzNtX0E4EvG1gpkMib31LpElc fmeUsBJEmwiv91xOQ5tiQ+DYRGMjymXl6qV3IHeilQlgeJa+VDvcOl1gP6dzEbY6Vn8F VmUYE3Ck5D7VcpDpMtZCiWrzL9bevetuhQ2DHCoJQ+DEDmogUii6BZXX3xhVgMF5p6ZL 4Sk4Qa4ZxyzQBb5xtSbndhBkZtEekOTDx3X06RH6yddvQk+WfUkbP721T2xPM7QNksuY QWoQ== X-Gm-Message-State: APjAAAWo4G7juEjh1ZG8mjfn0KhbrwtWxKCAWj4RjTAu99p4lKV03Gvd 2Dlst5EMLRJOVnVbro7OXmxwO8K2 X-Google-Smtp-Source: APXvYqxrvbOu1oSiDjib+NuzGTN7z8gQfiMFX7A3y5VCC/rtreeaGbESuDGwIDpqVIkFfTQdMMEz5Q== X-Received: by 2002:a5d:6b07:: with SMTP id v7mr21238221wrw.169.1562634701932; Mon, 08 Jul 2019 18:11:41 -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:41 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Jul 2019 03:10:47 +0200 Message-Id: <20190709011048.29601-5-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 30/31] h264_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 h264_metadata update the AVCodecParameters during init to align them with the changes at the bitstream level. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_metadata_bsf.c | 37 +++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index cbf2025fd4..1dfcee6a31 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -85,8 +85,8 @@ typedef struct H264MetadataContext { } H264MetadataContext; -static int h264_metadata_update_sps(AVBSFContext *bsf, - H264RawSPS *sps) +static int h264_metadata_update_sps(AVBSFContext *bsf, H264RawSPS *sps, + int *width, int *height, int *level) { H264MetadataContext *ctx = bsf->priv_data; int need_vui = 0; @@ -201,6 +201,14 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, CROP(bottom, crop_unit_y); #undef CROP + if (width && height) { + *width = 16 * (sps->pic_width_in_mbs_minus1 + 1) - crop_unit_x * + (sps->frame_crop_left_offset + sps->frame_crop_right_offset); + *height = 16 * (sps->pic_height_in_map_units_minus1 + 1) + * (2 - sps->frame_mbs_only_flag) - crop_unit_y * + (sps->frame_crop_top_offset + sps->frame_crop_bottom_offset); + } + if (ctx->level != LEVEL_UNSET) { int level_idc; @@ -260,6 +268,9 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, } else { sps->level_idc = level_idc; } + + if (level) + *level = sps->level_idc; } if (need_vui) @@ -347,7 +358,8 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) has_sps = 0; for (i = 0; i < au->nb_units; i++) { if (au->units[i].type == H264_NAL_SPS) { - err = h264_metadata_update_sps(bsf, au->units[i].content); + err = h264_metadata_update_sps(bsf, au->units[i].content, + NULL, NULL, NULL); if (err < 0) goto fail; has_sps = 1; @@ -571,7 +583,9 @@ static int h264_metadata_init(AVBSFContext *bsf) { H264MetadataContext *ctx = bsf->priv_data; CodedBitstreamFragment *au = &ctx->access_unit; - int err, i; + int err, i, width = -1, height = -1, level = -1; + int chroma_location = ctx->chroma_sample_loc_type; + int color_range = ctx->video_full_range_flag; err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_H264, bsf); if (err < 0) @@ -586,7 +600,8 @@ static int h264_metadata_init(AVBSFContext *bsf) for (i = 0; i < au->nb_units; i++) { if (au->units[i].type == H264_NAL_SPS) { - err = h264_metadata_update_sps(bsf, au->units[i].content); + err = h264_metadata_update_sps(bsf, au->units[i].content, + &width, &height, &level); if (err < 0) goto fail; } @@ -599,6 +614,18 @@ static int h264_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);