From patchwork Sat Dec 1 19:28:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11243 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 08BDC44D517 for ; Sat, 1 Dec 2018 21:31:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A786A68A2F5; Sat, 1 Dec 2018 21:31:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4DB2F68A3B2 for ; Sat, 1 Dec 2018 21:31:19 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id z5so8335283wrt.11 for ; Sat, 01 Dec 2018 11:31:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QftAsX2kY/N9xjR3yJyLMKzD1mCJIXBXdEb2PmLHJ0s=; b=irdVEKVu8rgazfifrD7MuFAZs6P4AucCK/SQ6H2DXQ8fAsyKoOIifj0ItsTethXd9b MCIagezoPKiUDLP1JM5nysd8ew+5xDQbFxdjm6RoM7FIUzLqkgQLBDfBYrdhAjsy6Zx1 J2IPy11MNlCobKDQ+Dobw/zQgdfWpus7S2Z5bocskw5ragqIUdlcsaSaErbx6GfmZ1QR vg2VaS66qHsCdamRSjdKV2ZMjnrxGw9wZ2iCini3ZH1Uj7z1nsQHtu7MNpEyeWNJfKS0 xOiptRUBS+V0WTQ3JbE4jS0oOpNvwGuQE+NnMkqzlHz7ETYIhxtonco62X8aNhx9l9oN yw6A== 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=QftAsX2kY/N9xjR3yJyLMKzD1mCJIXBXdEb2PmLHJ0s=; b=H1boJq3mgQbeN64rYvDHuk3EjLpgft0v6NMAdmbOgc9RZ9tjHickzX8WDp9uBDhXi0 cszdPHuoKdaA91HSsAUmqLQ2J0IX5Nymy/zEGF9d5jZEDo0fuSj3/HPH03Ne+lZTgKKO oWmwLNUhbJJu1qyWWikCvjnwNyUtYf9ZR94PzEY4hsIu8LUZJIxu7OuffLl+yARJK+W5 2yp8x0vdBg6Snr0YL+i3h8u1iuw5Q5zF9H2HAlgDfVq46wmmE01Y2i1Amr82v92hp/qv TRTiT7FPm/bNUsN2iweEwQ/7bf19raIdQ01ZmaANaNz6fN73JwYg6Z7p01vFSjCgNgWz yR7g== X-Gm-Message-State: AA+aEWYy+Pr1NKG88TcRNtllc5O/VlI2HvLeBhnSbV8u0ehyt9qN+LgZ PZNYUQaYxLNc5RBzffklxLwk1sL/ X-Google-Smtp-Source: AFSGD/Vy1EOQprWq04vQSdWq9JY64yjf/pE/fr2dmNLlVJPp55JD5WIZT4Gh425HB+k142gjlOKcDg== X-Received: by 2002:adf:9521:: with SMTP id 30mr8358456wrs.192.1543692685294; Sat, 01 Dec 2018 11:31:25 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id 5sm5045686wmw.8.2018.12.01.11.31.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 11:31:24 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Dec 2018 20:28:10 +0100 Message-Id: <20181201192810.852-9-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181201192810.852-1-andreas.rheinhardt@googlemail.com> References: <20181201192810.852-1-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 8/8] 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 efd6834a3c..c65c2aba2c 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -372,6 +372,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 26eb2d05d0..47f2ba12ac 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,9 @@ 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, + int *chroma_location) { H265MetadataContext *ctx = bsf->priv_data; int need_vui = 0; @@ -176,6 +179,9 @@ static int h265_metadata_update_sps(AVBSFContext *bsf, ctx->chroma_sample_loc_type; sps->vui.chroma_loc_info_present_flag = 1; need_vui = 1; + + if (chroma_location && sps->chroma_format_idc == 1) + *chroma_location = 1 + ctx->chroma_sample_loc_type; } if (ctx->tick_rate.num && ctx->tick_rate.den) { @@ -224,6 +230,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; @@ -304,7 +317,8 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) 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, NULL); if (err < 0) goto fail; } @@ -335,7 +349,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, chroma_location = -1; err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_HEVC, bsf); if (err < 0) @@ -355,7 +369,9 @@ 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, + &chroma_location); if (err < 0) goto fail; } @@ -368,6 +384,21 @@ static int h265_metadata_init(AVBSFContext *bsf) } } + if (ctx->full_update) { + int color_range = ctx->video_full_range_flag == -1 ? -1 : + ctx->video_full_range_flag + 1; + + 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_uninit(ctx->cbc, au); @@ -439,6 +470,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 } };