From patchwork Wed Jun 19 23:45:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13637 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 A11C1448B5A for ; Thu, 20 Jun 2019 02:58:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5AFDC68ABBA; Thu, 20 Jun 2019 02:56:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 87E0B68AB27 for ; Thu, 20 Jun 2019 02:55:53 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id f9so1003745wre.12 for ; Wed, 19 Jun 2019 16:55:53 -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=coNpnskT1PE/wgHkgeCnU4dVpNNTilDG5K87wcip/ik=; b=BMl6D+7dstW/OsSIpJpgfNOOQuWpmVwOjg0+B0AZPgDrdSEZr0MEM5XWunFJRy5mc9 17JOtCqlnrYXmUrWj+5OLH3uam6eHkk1wsL7wcRJz0jQ3g6Q32pnDBRTI6jRQooDFMxQ AKLmnRWXKYfUxHTzcAMyrEWMFsE+fdQmc95ZL2/cPz5+UGqR+n5S15S+utanNtqWgwFt YFr6N/i6saDWtoC5nSxRDLwmPvhuJbcCaCzOknoTmWT8+q1nnMPq+auKq+E3wDqdt0jA EwWal3x/+HB/5QijLnYBsOtxCddxD6wmMV9Nzc2fhy7JtPA54SkPCbxAhun33FDTzgQf +23g== 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=coNpnskT1PE/wgHkgeCnU4dVpNNTilDG5K87wcip/ik=; b=UtUwqtY28uk7CtOuMVkWnbqyC8rflgZfpfMKapYvbmvMlacmOhIOydHpRjG17aPTDI e7rfzcu0S79YKq1TRKTwpc81ztqjtBE3SbUOFX8LA3znFQjHah/y0Q5hm553ft3o9dYG 3eCRIDzexETcvPQgh6lyf+LTtOCrmqySWYj8Hj3jdlEH0LDV9U7QTLVoay1v3p17ZEyt 8F/zBAnbU53+3gzhR6X8yJpzUWJSFGKoSbVP+myL2IvIK50oWSO4GhckRCc5NF07EHMF 1koKpLCFtR/MDDmQoz1uHhqs1IwCC5ZE5n/LSKZeaE+FKJqQsX6oboNXYPhgC5lODGb7 vbgQ== X-Gm-Message-State: APjAAAXyjFQxUAEXBiNzaQgaN1EbRKGjqCLNwd02JKmeRbuH6tELvOyC QiQA71ufk+9NSoIrw8goNEX2Bp/O X-Google-Smtp-Source: APXvYqxgH113RvZtSNmWGOxpJv99kNGDdcE49ayNnYlslfd2CCuIqJhqwGD20rpVN55z1afBuJjPzA== X-Received: by 2002:a5d:4fc1:: with SMTP id h1mr3191620wrw.83.1560988552839; Wed, 19 Jun 2019 16:55:52 -0700 (PDT) Received: from localhost.localdomain (ipbcc063db.dynamic.kabel-deutschland.de. [188.192.99.219]) by smtp.gmail.com with ESMTPSA id t63sm2758989wmt.6.2019.06.19.16.55.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 16:55:52 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jun 2019 01:45:21 +0200 Message-Id: <20190619234521.15619-23-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190619234521.15619-1-andreas.rheinhardt@gmail.com> References: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> <20190619234521.15619-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 31/31] hevc_metadata: Update AVCodecParameters 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 adds an option to also update the AVCodecParameters to align them with the changes at the bitstream level. It is on by default. Given the importance of correct frame dimensions they are updated even when the new option is disabled. Notice that for field-based HEVC the derived height is the height of a frame, which deviates from current FFmpeg behaviour. This commit also adds documentation for the new value. Signed-off-by: Andreas Rheinhardt --- doc/bitstream_filters.texi | 8 +++++++ libavcodec/h265_metadata_bsf.c | 44 ++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 8030be233c..cc50a4e9fe 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -375,6 +375,14 @@ will replace the current ones if the stream is already cropped. These fields are set in pixels. Note that some sizes may not be representable if the chroma is subsampled (H.265 section 7.4.3.2.1). +@item full_update +If this is set, an effort is made to update the AVCodecParameters in addition +to the bitstream. If unset, muxers might add header information based upon +the old AVCodecParameters that contradicts and potentially precedes the +changes made at the bitstream level. On by default. + +The frame dimensions are always updated and not affected by this option. + @end table @section hevc_mp4toannexb diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c index 2f28342a26..71bad9b64a 100644 --- a/libavcodec/h265_metadata_bsf.c +++ b/libavcodec/h265_metadata_bsf.c @@ -58,6 +58,8 @@ typedef struct H265MetadataContext { int crop_right; int crop_top; int crop_bottom; + + int full_update; } H265MetadataContext; @@ -89,8 +91,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; @@ -224,6 +226,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; @@ -305,7 +314,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; } @@ -331,7 +341,7 @@ 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; err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_HEVC, bsf); if (err < 0) @@ -351,7 +361,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; } @@ -364,6 +375,26 @@ static int h265_metadata_init(AVBSFContext *bsf) } } + if (ctx->full_update) { + int color_range = ctx->video_full_range_flag; + int chroma_location = ctx->chroma_sample_loc_type; + + if (color_range >= 0) + color_range++; + if (chroma_location >= 0) + chroma_location++; + + ff_cbs_update_video_parameters(ctx->cbc, bsf->par_out, -1, -1, + width, height, -1, color_range, + ctx->colour_primaries, + ctx->transfer_characteristics, + ctx->matrix_coefficients, + chroma_location, -1); + } else + ff_cbs_update_video_parameters(ctx->cbc, bsf->par_out, -1, + -1, width, height, -1, -1, + -1, -1, -1, -1, -1); + err = 0; fail: ff_cbs_fragment_reset(ctx->cbc, au); @@ -437,6 +468,9 @@ static const AVOption h265_metadata_options[] = { OFFSET(crop_bottom), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, HEVC_MAX_HEIGHT, FLAGS }, + { "full_update", "Update not only bitstream, but also AVCodecParameters", + OFFSET(full_update), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS}, + { NULL } };