From patchwork Tue Jul 9 01:10:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13862 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 3174E44758E for ; Tue, 9 Jul 2019 04:11:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0783F68AE45; Tue, 9 Jul 2019 04:11:17 +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 1245D68AD93 for ; Tue, 9 Jul 2019 04:11:10 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id r1so12748920wrl.7 for ; Mon, 08 Jul 2019 18:11:10 -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=pYI6is3lnX0cPk4X91OLA2l1/YdMegVNMEccBtp8XVk=; b=CX7mDkATHKHxhLDWX94YXhGlYbSJg55eTEQTz1Ih5q7eWPLEIoed4RXCZT4N5qVR5S B31T+4TP8wCCpmmgzu0LLpv4/Aafhr47T3ivOYJpH5OQArdzngUiLsoIMxIpHnkIU1jm 7EcpY6sdr1PPIJSiKCaFQ/WQ2hQWK/ExS9rPvs88Y5pMLN/6DYDPV4D1+1UVNAl4KtbI mJ82fXuEGW14a2F2sg+hhgKKxuij/7YgWugGkVo64upAVBvcVCmLPZz6HvgA+6eEeJ9+ atDb/DsSXAObizv3CEUYz4R9uEbcqhKoy20Ipo6KaOi56JmiHTRvzPlVoG9s+x/V697s 9uhQ== 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=pYI6is3lnX0cPk4X91OLA2l1/YdMegVNMEccBtp8XVk=; b=S/lTyY9WVeulbs/B25JDvAF5RTSvPh1bMVOHmH3sAa3r93G/vlbb8vREz98y9kIpe4 EM8P5VX5s5XYG8uqmT3WKgMCqPOmOBjym2vgH3XHFqp3TjThbLKDQsPI1WObisR5kobp KqhoaegHx47SnIPm3MhVrtX8oQFxEbtPsR9FOsOBhFfIj0iX3ky1+sBJC+Y4qeymiKm/ S63qgOIiX1jFo+jTVxsxs2T9KSR5Ir5EhC4dxHQOPMU2cKcTBwnEo/d+axkRTZ4jycqN Bak7E9R41MsB990kQPQBHW9BrBRIxAYy75GNPodbT2vMoyE7IREVr7rO9ufCvvYcCmG1 4wsg== X-Gm-Message-State: APjAAAVu3qX9HeBbQfrbpiW4/vzRdH0n5RFKxpCjYygkYSMN+5cfEffZ KbFz1IrcyU6PxaXnv8zltcW6IynU X-Google-Smtp-Source: APXvYqwSpXJAVuWGslBpflmlI6DGpmGzj8+WmyZC4ACJJqfvI0ncD008t6wss1V5KLUuQ6SUf74r8g== X-Received: by 2002:a05:6000:10c1:: with SMTP id b1mr18102496wrx.126.1562634669266; Mon, 08 Jul 2019 18:11:09 -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.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 18:11:08 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Jul 2019 03:10:43 +0200 Message-Id: <20190709011048.29601-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <7166cd5e-8604-3842-3191-e0d47d7ac934@gmail.com> References: <7166cd5e-8604-3842-3191-e0d47d7ac934@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 26/31] av1_metadata: 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 and thereby brings av1_metadata in line with the expected behaviour for bitstream filters. Signed-off-by: Andreas Rheinhardt --- libavcodec/av1_metadata_bsf.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c index dd0c9b6148..6821a3e102 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -52,7 +52,9 @@ typedef struct 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 +81,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 +92,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 +143,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; } @@ -188,7 +195,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) @@ -204,7 +211,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; } @@ -217,6 +225,22 @@ static int av1_metadata_init(AVBSFContext *bsf) } } + 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);