From patchwork Wed Jun 19 23:45:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13633 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 4749C448AA5 for ; Thu, 20 Jun 2019 02:55:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2DD3D68AB90; Thu, 20 Jun 2019 02:55:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1836668AB40 for ; Thu, 20 Jun 2019 02:55:49 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id s15so1240178wmj.3 for ; Wed, 19 Jun 2019 16:55:49 -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=J+cK6iV1dljEf0qiSZdL959PBeuLtlE9LQlWqnGEKO0=; b=aEFmtGUhHkWq7jm0zVTPfhVr7qPsD1M/I/aJ2CBaBRpqLOCIozeu051zLtrIpRxSq0 fhdZWlxylVD5ahGNiH4/r0N+ONS0+U5JgM17jh1Fz/k9f21gFtazqSsDdXhyGKCXKVmp 5uNTPLLAmlFKq3a2DM/Tf5sTTxE5SahD4ioldQv0cTLdfxtXegzRMeRQlYl+f+VFltSB Cd8iVFkVmR/INb//jH/U/JPpCZv34Ogwlsp/MXX4lDVcYmCZwZa/5IaeQrEy7P0shF0Z TQSzFulAifZ0HfA0BxCXcqYtARqLE/sDHvTl3X9gehX2w3PCdo62juGvT7lhOlqacxgG RY3A== 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=J+cK6iV1dljEf0qiSZdL959PBeuLtlE9LQlWqnGEKO0=; b=V4IoREtR/mTzAM0LtitZ84ME2evJZf8BKMZiPzlscteH8IPFlAK2+gKkzSx9friivI YXbWK1GWwlvOQHsgt//TDC0pbgLpdkoNKj6XbqChuaNyUGzT8553tT+Q2WLKI6sRjtux jYBmgY8Fj2DddhBrlAETHvF4ggZ4P5Mbwzm50nym8zN+DogtFXi6XcISHpGlAqUN4WMx 66SqBObogPTDTowNknDIty1MtSChy403TWYAl1uswo3kzxT054yz1mhMIqsh1g9+pAXa U3z94+wLgUJqcSG01u90u55X3qHFeEt04Lttr4WvzRH3inpVEos0sKxfMQMxRuXFJlgA GyBw== X-Gm-Message-State: APjAAAU7/Jcj1wQAMS3uWqgwGKq4hKatPvnUnQKO4egR60+qJ21B5yXE yyF4yWyEIl/bnsfSniK2/Gr741mW X-Google-Smtp-Source: APXvYqzPc05ICz9NnPUhew38/JtcNFF34o6VD3cmGcziLnEWpfRevFbDAisSXQ9EbNuxwh/LcySKqg== X-Received: by 2002:a1c:2c6:: with SMTP id 189mr9759836wmc.108.1560988548336; Wed, 19 Jun 2019 16:55:48 -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.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 16:55:47 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jun 2019 01:45:16 +0200 Message-Id: <20190619234521.15619-18-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 26/31] av1_metadata: Add option to update codec parameters 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" Up until now, this BSF only changed the bitstream and the extradata, not the rest of the AVCodecParameters. The result is that e.g. some muxers use outdated information to write header information that conflicts with (and potentially precedes) the new information at the bitstream level, so that using the bitstream filter might not have the desired effect. This commit changes this. It adds a mechanism by which the new information can be used to update the AVCodecParameters, too. This is the new default and an option has been added to revert to the old behaviour. Signed-off-by: Andreas Rheinhardt --- doc/bitstream_filters.texi | 6 ++++++ libavcodec/av1_metadata_bsf.c | 39 +++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 40e8adad0f..f625c8f768 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -90,6 +90,12 @@ has a fixed framerate. Ignored if @option{tick_rate} is not also set. @item delete_padding Deletes Padding OBUs. +@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. + @end table @section chomp diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c index 7d9d15b1a0..fce1a194b7 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -48,11 +48,15 @@ typedef struct AV1MetadataContext { int num_ticks_per_picture; int delete_padding; + + int full_update; } AV1MetadataContext; static int av1_metadata_update_sequence_header(AVBSFContext *bsf, - AV1RawSequenceHeader *seq) + AV1RawSequenceHeader *seq, + int *color_range, + int *chroma_sample_position) { AV1MetadataContext *ctx = bsf->priv_data; AV1RawColorConfig *clc = &seq->color_config; @@ -79,6 +83,8 @@ static int av1_metadata_update_sequence_header(AVBSFContext *bsf, "on RGB streams encoded in BT.709 sRGB.\n"); } else { clc->color_range = ctx->color_range; + if (color_range) + *color_range = ctx->color_range + 1; } } @@ -88,6 +94,8 @@ static int av1_metadata_update_sequence_header(AVBSFContext *bsf, "can only be set for 4:2:0 streams.\n"); } else { clc->chroma_sample_position = ctx->chroma_sample_position; + if (chroma_sample_position) + *chroma_sample_position = ctx->chroma_sample_position; } } @@ -137,7 +145,8 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) for (i = 0; i < frag->nb_units; i++) { if (frag->units[i].type == AV1_OBU_SEQUENCE_HEADER) { obu = frag->units[i].content; - err = av1_metadata_update_sequence_header(bsf, &obu->obu.sequence_header); + err = av1_metadata_update_sequence_header(bsf, &obu->obu.sequence_header, + NULL, NULL); if (err < 0) goto fail; } @@ -191,7 +200,7 @@ static int av1_metadata_init(AVBSFContext *bsf) AV1MetadataContext *ctx = bsf->priv_data; CodedBitstreamFragment *frag = &ctx->access_unit; AV1RawOBU *obu; - int err, i; + int err, i, color_range = -1, chroma_sample_position = -1; err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_AV1, bsf); if (err < 0) @@ -207,7 +216,8 @@ static int av1_metadata_init(AVBSFContext *bsf) for (i = 0; i < frag->nb_units; i++) { if (frag->units[i].type == AV1_OBU_SEQUENCE_HEADER) { obu = frag->units[i].content; - err = av1_metadata_update_sequence_header(bsf, &obu->obu.sequence_header); + err = av1_metadata_update_sequence_header(bsf, &obu->obu.sequence_header, + &color_range, &chroma_sample_position); if (err < 0) goto fail; } @@ -220,6 +230,24 @@ static int av1_metadata_init(AVBSFContext *bsf) } } + if (ctx->full_update) { + if (chroma_sample_position >= 0) { + static const uint8_t conversion_table[4] = { + AVCHROMA_LOC_UNSPECIFIED, + AVCHROMA_LOC_LEFT, + AVCHROMA_LOC_TOPLEFT, + AVCHROMA_LOC_UNSPECIFIED + }; + chroma_sample_position = conversion_table[chroma_sample_position]; + } + + ff_cbs_update_video_parameters(ctx->cbc, bsf->par_out, -1, -1, -1, -1, + -1, color_range, ctx->color_primaries, + ctx->transfer_characteristics, + ctx->matrix_coefficients, + chroma_sample_position, -1); + } + err = 0; fail: ff_cbs_fragment_reset(ctx->cbc, frag); @@ -286,6 +314,9 @@ static const AVOption av1_metadata_options[] = { OFFSET(delete_padding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS}, + { "full_update", "Update not only bitstream, but also AVCodecParameters.", + OFFSET(full_update), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS}, + { NULL } };