From patchwork Tue Jul 9 01:10:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13864 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 5D3A744758E for ; Tue, 9 Jul 2019 04:11:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4AF1F68AF48; Tue, 9 Jul 2019 04:11:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1368268AF28 for ; Tue, 9 Jul 2019 04:11:41 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id n4so19117561wrs.3 for ; Mon, 08 Jul 2019 18:11:41 -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=p7RxZ3gSxW/UGVm+WUWiQhgBrPhBJS9swR4SXbw0Ifk=; b=BYTobMzZaPg+BewYGbquwycMQNM7GLNTx59s5W2vanG3SS/jkzJqa1f5mPXx57PehQ U15Hv4+ungV+bSP2ZGKOJUybD9BsC7BS99cxiw6MQ5UXhwoHBfD0cWzEkkQINb4qaRK8 4y/f9y2VVD2c4EMqJUqOJrneBV+fg5LtQfrpbEgdQdIT4Xid6bh8GnKd4Pam3eDz9pbg 1zMIeJyU8Iu+V2tAk/xPTYJzx0e0GoSfl4TyHl+5tPqeW9DJrC8az4tQwIi+9WJgdkhj 8MF2gi7wGmFpPX4tj8+tApjDj8jdQktXTcWRqOIlLyBDPgGxfI+n6li0eW7Prha9/yKK kJvw== 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=p7RxZ3gSxW/UGVm+WUWiQhgBrPhBJS9swR4SXbw0Ifk=; b=iiadyqwL8bJi+6Fh6jqpaAwcq+EWX/oIgYvuWdPMzzKC4p0tgQ8vR0L0HKQZlou47w EuPWKZfEOZKvOv5kctD/vUJxZtJhPEXcArSTmyRD3k8u8vIN9HmL50LlEZfRxzr9FKYn VTRWcBsxcEsB2RGNMEv96ripYTgJEv1afdJGhsrqb7i75vThKXX7qWWI3rpdP5iCPKq9 xRk3nxG+LDjdywJmSJ0QKMDcBKjETZ3aoG+/1rx6uKlC3KQ0vIhsEHIc4/nNCJgE9Ir4 1hVUSHhA9Tzk0o7Em2sWpkmYWjtrBz6vlSi85c3APx+QcS0AG4bOk5aPRYz7fr/4TJf/ RZoQ== X-Gm-Message-State: APjAAAVCw9xEps3wRUuGw1nGeHLmRu9v+YwppFfiuG5KTuBA4GNtd8h5 mmFaFx8vSvFpXsXG2wkZyvHBYFPC X-Google-Smtp-Source: APXvYqwxYbQ6lp/8GJfDW/2pZl7AQz0B8jgvyXqVuZkYP/VaPwKKa7owDwdnkMgZb2sTCTGMaSy3gA== X-Received: by 2002:adf:dcc6:: with SMTP id x6mr21266610wrm.322.1562634700361; Mon, 08 Jul 2019 18:11:40 -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.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 18:11:39 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Jul 2019 03:10:45 +0200 Message-Id: <20190709011048.29601-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709011048.29601-1-andreas.rheinhardt@gmail.com> References: <7166cd5e-8604-3842-3191-e0d47d7ac934@gmail.com> <20190709011048.29601-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/31] vp9_metadata: Improve spec-compliance and warnings 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" The earlier version had three deficits: 1. It allowed to set the stream to RGB although this is not allowed when the profile is 0 or 2. 2. If it set the stream to RGB, then it did not automatically set the range to full range; the result was that one got a warning every time a frame with color_config element was processed if the frame originally had TV range and the user didn't explicitly choose PC range. Now one gets only one warning in such a situation. 3. Intra-only frames in profile 0 are automatically BT.601, but if the user wished another color space, he was not informed about his wishes being unfulfillable. The commit also improves the documentation about this. Signed-off-by: Andreas Rheinhardt --- doc/bitstream_filters.texi | 8 ++++--- libavcodec/vp9_metadata_bsf.c | 40 ++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index a6a5a331f5..47de4c7116 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -657,7 +657,9 @@ Modify metadata embedded in a VP9 stream. @table @option @item color_space -Set the color space value in the frame header. +Set the color space value in the frame header. Note that any frame +set to RGB will be implicitly set to PC range and that RGB is +incompatible with profiles 0 and 2. @table @samp @item unknown @item bt601 @@ -669,8 +671,8 @@ Set the color space value in the frame header. @end table @item color_range -Set the color range value in the frame header. Note that this cannot -be set in RGB streams. +Set the color range value in the frame header. Note that any value +imposed by the color space will take precedence over this value. @table @samp @item tv @item pc diff --git a/libavcodec/vp9_metadata_bsf.c b/libavcodec/vp9_metadata_bsf.c index 1bde1b96aa..52e962b1c0 100644 --- a/libavcodec/vp9_metadata_bsf.c +++ b/libavcodec/vp9_metadata_bsf.c @@ -33,7 +33,7 @@ typedef struct VP9MetadataContext { int color_space; int color_range; - int color_range_rgb_warned; + int color_warnings; } VP9MetadataContext; @@ -56,20 +56,36 @@ static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) for (i = 0; i < frag->nb_units; i++) { VP9RawFrame *frame = frag->units[i].content; VP9RawFrameHeader *header = &frame->header; + int profile = (header->profile_high_bit << 1) + header->profile_low_bit; + + if (header->frame_type == VP9_KEY_FRAME || + header->intra_only && profile > 0) { + if (ctx->color_space >= 0) { + if (!(profile & 1) && ctx->color_space == VP9_CS_RGB) { + if (!(ctx->color_warnings & 2)) { + av_log(bsf, AV_LOG_WARNING, "Warning: RGB " + "incompatible with profiles 0 and 2.\n"); + ctx->color_warnings |= 2; + } + } else + header->color_space = ctx->color_space; + } - if (ctx->color_space >= 0) { - header->color_space = ctx->color_space; - } - if (ctx->color_range >= 0) { - if (ctx->color_range == 0 && - header->color_space == VP9_CS_RGB && - !ctx->color_range_rgb_warned) { - av_log(bsf, AV_LOG_WARNING, "Warning: color_range cannot " - "be set to limited in RGB streams.\n"); - ctx->color_range_rgb_warned = 1; - } else { + if (ctx->color_range >= 0) header->color_range = ctx->color_range; + if (header->color_space == VP9_CS_RGB) { + if (!(ctx->color_warnings & 1) && !header->color_range) { + av_log(bsf, AV_LOG_WARNING, "Warning: Color space RGB " + "implicitly sets color range to PC range.\n"); + ctx->color_warnings |= 1; + } + header->color_range = 1; } + } else if (!(ctx->color_warnings & 4) && header->intra_only && !profile && + ctx->color_space >= 0 && ctx->color_space != VP9_CS_BT_601) { + av_log(bsf, AV_LOG_WARNING, "Warning: Intra-only frames in " + "profile 0 are automatically BT.601.\n"); + ctx->color_warnings |= 4; } }