From patchwork Sat Dec 1 19:28:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11247 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 80BA944D517 for ; Sat, 1 Dec 2018 21:31:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A50F68A38A; 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-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3DF7268A31C for ; Sat, 1 Dec 2018 21:31:12 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id v6so8315969wrr.12 for ; Sat, 01 Dec 2018 11:31:19 -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=+NCRjTqAtTWlpovwP960aWqakecz1zw+junBISLPrhs=; b=YKyLEht0veB8EdiUL3uMU/oamsJsh9YkfRq1biRrKtaB+8p4T/RZKkGa8ONHCtDjO3 tp4BjcSFSegAiQ1A2oIv24Oy+oMVB7m4hlV9BeK4TsF4SrIjZIoOn+aeA0VDW4MLZPX6 uK1wQEcPC84x6gzrRdzXHCAGc2qK26Ji86Xr+KqQRKQzmU3Tev5mVpy0UG2rRPPeT6Yd EQDI/GqyOBxni/YfON/EfXi1WaF5zXnY6BZGH835KOe/4q5zxmeNt6kU/sEAHz0mBjdB aNZWqC7IbwQ47cOzQtB2TbTDtPUUYlNClFitLh+ZnPWhW2QYVA0B9dR2gSBx6t4MjUAM W+0A== 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=+NCRjTqAtTWlpovwP960aWqakecz1zw+junBISLPrhs=; b=Ruej05KxEu2aONC1Hn9YPFTP2jqAdgSLHAWsjKrNAbZuMxE3PI23N1CnY5FvBaF7nu 5dqOqBsawlpeq/y4nQkyQflD56RgD5AwRR4gNG1ZC2m2BeElZwibQcbBMjZ+pbAwx3f9 VXYSJXmEqtARKCVrMT0hS1+E+wjm6n8tADeO0pmVdfsJmaBWJHQdBgJGHVpH1JghTRBr 4OwN3fREpmyZgPdUuAobV6niD9HBm5q81hK9iq1lB1NaGH9EM+S/8i/9OS5+WsSdqtGH EnOTa49Dab4NTDf1PLIdy/kpLg5lfbKc6e4Y6S/kpCAJ6XDberYVV4lN63x+ehm0hrUg 1llw== X-Gm-Message-State: AA+aEWZxqSCpcp+n0JbsXVkZ9teSYCgI0w4rs1ldi+Xwgl3rKsmPkSVF oeMq1+bDu6DnKYl7VUuj3rpLGBDR X-Google-Smtp-Source: AFSGD/Vy3gtiJBKVEyG7LSXsEVS9U5JnvRSPCZjGEENpTkU162RPlXp7lhofHIcS/0K4XMbKb8BQhQ== X-Received: by 2002:adf:e247:: with SMTP id n7mr8457432wri.205.1543692678417; Sat, 01 Dec 2018 11:31:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 11:31:17 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Dec 2018 20:28:07 +0100 Message-Id: <20181201192810.852-6-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 5/8] 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 a1558c5d69..7ab535b58c 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -656,7 +656,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 @@ -668,8 +670,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 be010edc3f..9170083c06 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; @@ -57,20 +57,36 @@ static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *out) 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) { + 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 != -1 && 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; } }