From patchwork Sat Dec 1 19:28:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11242 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 60D4544D3E3 for ; Sat, 1 Dec 2018 21:30:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0FF6468A283; Sat, 1 Dec 2018 21:30:56 +0200 (EET) 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 E5659689FC8 for ; Sat, 1 Dec 2018 21:30:49 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id x10so8334234wrs.8 for ; Sat, 01 Dec 2018 11:30:56 -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=4hpv2SBYZHHiLXc02hX+5QRi8D1PqcmQ3o9xHT3m9ZI=; b=n55JpwCcCE4pd1OdrWyerWCGE1ZxuN6MGdfXa5fqAY+DUANCQOIX9TMT5fgiy6IZAa 8eNYi+M+4G3LTcQ+dwsNrZmpi0R02umiRSCZCVCHWT7BDsDfIupswwO9ivH0LXZs5bYF LvqA+xSlksvkt1OAGuZqcbwKEA7HiPm/jVM3xoJ/hrxfKqKTW+LoN3eBYVSLnD4Defwm rwqP9EaQMWHadmry1Txla0nhj1WUNNlQ/pTqS3RxJxFSsyoB9riAqK8gNUB8CPR7fcii TStVbYz1EPJsxQvkevVaqw7Z5rvLALAyKHjEUmRpLvPYD1Ay6WZSJPRr6UCnMHbsiuxV OGLg== 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=4hpv2SBYZHHiLXc02hX+5QRi8D1PqcmQ3o9xHT3m9ZI=; b=nx2r83lrAkEyw3lfTjW4MJw+wtmDS9Jg2qlnTjtTNiH0DkaVBPc5aiTMpzfU/Eyq1U UybzLpDefXhuPZTDqnoaAywsgjVnrExSbcrQdluIMblEk3BHkaUGbOx78jK6x+bwT3TW pKHFOfqSJ0iL7iNqRi3iolkE1T9iT5ONtVrzwidN94tl5Lqplo+n2EouVnUdHsLFA3Ck z8Z5ISlztZGj7+QnNAW34tFHWtzb8uYgqxY91TnLH2ulUnU5KPRmIPB0jEfHsOv+nyVF qIUOiXKoYkDgAO6HLtmIH6dI30lp+LqM62fx9piuj6cBDtpdFX+xolXrcnZVR8HWKqLU EZhQ== X-Gm-Message-State: AA+aEWakFU+eTC+sxuEK/gsbRfsHcCgJ/0LrhMOjpbArksFVYaAH/RnF oVn0ifae+/uqubKD6nEp5pxjVILx X-Google-Smtp-Source: AFSGD/VPJSA/IPiPlHkK88RbQiBMMmuz7PiEhAsT40zhKpdvzcLyoYNCEcE6xTkN/B7qX3d19c3AUQ== X-Received: by 2002:adf:9521:: with SMTP id 30mr8357621wrs.192.1543692655882; Sat, 01 Dec 2018 11:30:55 -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.30.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 11:30:55 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Dec 2018 20:28:04 +0100 Message-Id: <20181201192810.852-3-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 2/8] av1_metadata: Add option to update video 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, not the AVCodecParameters. The result is that e.g. some muxers use outdated information to write header information that conflicts with (and precedes) the new information at the bitstream level, so that the updates might not lead to the desired change. 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 | 43 +++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 15c578aa8a..80df345f26 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -87,6 +87,12 @@ the timing info in the sequence header. Set the number of ticks in each picture, to indicate that the stream has a fixed framerate. Ignored if @option{tick_rate} is not also set. +@item full_update +If this is set, the AVCodecParameters are updated 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 52d383661f..0c8d00acea 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -46,11 +46,15 @@ typedef struct AV1MetadataContext { AVRational tick_rate; int num_ticks_per_picture; + + 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; @@ -82,6 +86,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; } } @@ -91,6 +97,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; } } @@ -135,7 +143,8 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out) 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; } @@ -184,7 +193,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) @@ -200,7 +209,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; } @@ -213,6 +223,28 @@ static int av1_metadata_init(AVBSFContext *bsf) } } + if (ctx->full_update) { + if (chroma_sample_position >= 0) { + const int conversion_table[4] = { AVCHROMA_LOC_UNSPECIFIED, + AVCHROMA_LOC_LEFT, + AVCHROMA_LOC_TOPLEFT, + AVCHROMA_LOC_UNSPECIFIED }; + chroma_sample_position = conversion_table[chroma_sample_position]; + } + + if (ctx->color_range >= 0) + ctx->color_range++; + + 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); + + if (ctx->color_range != -1) + ctx->color_range--; + } + err = 0; fail: ff_cbs_fragment_uninit(ctx->cbc, frag); @@ -273,6 +305,9 @@ static const AVOption av1_metadata_options[] = { OFFSET(num_ticks_per_picture), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS }, + { "full_update", "Update not only bitstream, but also AVCodecParameters.", + OFFSET(full_update), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS}, + { NULL } };