From patchwork Sat Dec 1 19:28:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11246 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 2DFF844D517 for ; Sat, 1 Dec 2018 21:31:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D58C068A3A2; Sat, 1 Dec 2018 21:31:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57CAF68A326 for ; Sat, 1 Dec 2018 21:31:17 +0200 (EET) Received: by mail-wm1-f67.google.com with SMTP id a18so2048079wmj.1 for ; Sat, 01 Dec 2018 11:31:24 -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=I/ojZWy/d8taf28LlXKQW5rQaarFZv9gDjIDQG/viRc=; b=jlnOtuzfUNq+GjTJdtEU8s0rxmM6zA2iAAv4dKQfoYf6+QPL9HGNFycQZB2+Z/NNQT qXW32lrI3G26yHvhMvdk7iCDOxjlawLRCY4UkY06BmMzax/OnmkJa+yH3zKJ1kkjtFAr dZOZI2eQW1rlfevdFv97YOqBY/2XyhrBte4+C5tLGptdjy45PVvdPwQbR8Ab2a9iRBf/ RkN0a3Ge+dnpE63Dnk9X6TYs0azFmrj7dX9ITPJXqjA2aYaQyGBaNcQTfB8DGhF3S1iS 3vwWnUAG6kfBZ0DP8KWK6LYkLtQOKlPvzQacEq/2T5mQrL8du9vhQ/xH3vIeVmjyEOSP YRHA== 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=I/ojZWy/d8taf28LlXKQW5rQaarFZv9gDjIDQG/viRc=; b=pO0jlM23xmckkpy3ujMHjxY9rIb4TQp4qGvJemYXBz4My6fk2xbPPSJ4UfyR8KRSie lLedXGI3hZd4oVVEaZsRlGRt1nv2ZOWsAaemLekEsQ0E8aWnStjRBDwCM2IH5naL7HIF V0WYzcy5Zaudjzs7nYHkgtVG794dMEjcII/dO1TGymH4GCUrIr2mLGoE4gpqKZrNq9Bf qXOxxQ6qU88vEw2deAYZOze24H80r6dOX2vqU1GE3JD5yzkwnnnCIbd7QW+WJWqDlXS9 ZzB+ZQ5kLt1u8hUJoKM7aBDGOOpW+FNqFxmaPUXLD83h+RJe6OJUUrlAeDHGL2Izj+Df G7Rw== X-Gm-Message-State: AA+aEWbb2fzYc5fl37WNLlvCVi/mRaSNDUCUAqUaQyclRVzxDlhHQZ+E ubWOQn9v4pD6Jpzu91zWfjk/+6WO X-Google-Smtp-Source: AFSGD/XjwORpMxbAk+gETpt8Z3/dih87mEEaSiEtPPsfdRKDmtjdAYralxx3TgGvpZLyWqce02WHjA== X-Received: by 2002:a1c:20cb:: with SMTP id g194mr2908907wmg.77.1543692683387; Sat, 01 Dec 2018 11:31:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 11:31:22 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Dec 2018 20:28:09 +0100 Message-Id: <20181201192810.852-8-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 7/8] h264_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. The commit also adds documentation for the new option. Signed-off-by: Andreas Rheinhardt --- doc/bitstream_filters.texi | 8 ++++++ libavcodec/h264_metadata_bsf.c | 48 ++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index f5bf4aa93e..efd6834a3c 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -282,6 +282,14 @@ level_idc value (for example, @samp{42}), or the special name @samp{auto} indicating that the filter should attempt to guess the level from the input stream properties. +@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 h264_mp4toannexb diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index e674f2a88d..9ed0af26ee 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -82,11 +82,14 @@ typedef struct H264MetadataContext { int flip; int level; + + int full_update; } 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, + int *chroma_location) { H264MetadataContext *ctx = bsf->priv_data; int need_vui = 0; @@ -172,6 +175,9 @@ static int h264_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) { @@ -216,6 +222,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; @@ -269,6 +283,9 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, } else { sps->level_idc = level_idc; } + + if (level) + *level = sps->level_idc; } if (need_vui) @@ -359,7 +376,8 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) 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, NULL); if (err < 0) goto fail; has_sps = 1; @@ -618,7 +636,7 @@ 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, chroma_location = -1; err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_H264, bsf); if (err < 0) @@ -633,7 +651,9 @@ 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, + &chroma_location); if (err < 0) goto fail; } @@ -646,6 +666,21 @@ static int h264_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, level, + 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); @@ -776,6 +811,9 @@ static const AVOption h264_metadata_options[] = { { LEVEL("6.2", 62) }, #undef LEVEL + { "full_update", "Update not only bitstream, but also AVCodecParameters", + OFFSET(full_update), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS}, + { NULL } };