From patchwork Sun Dec 3 11:19:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 6522 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp3234381jah; Sun, 3 Dec 2017 03:19:54 -0800 (PST) X-Google-Smtp-Source: AGs4zMZWt0viE5xfaoD0fDnuDY6OHPi/shAzB1CEalPy6qSlEIAzlM/SywjzVTtYJ2BfSWGMVjgp X-Received: by 10.28.57.11 with SMTP id g11mr5159680wma.92.1512299993909; Sun, 03 Dec 2017 03:19:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512299993; cv=none; d=google.com; s=arc-20160816; b=z2AS/ZJsZ7EMJR1q4sCihKZIzXnuxx3pHcqeC9Zb3u3AZBrZGxIYSJDNCBC+G+Prh4 UnoGRoP3cpsLaYeQ3tGrQyXaUpul+ytnyAOfWGlukzEY3FNJt5LsqvifmT4Q1QBHKwim wxrLMFyRDlyj93ez8Qzu7+ViXR8l3l8VTDr0Ky02UdSRo1YNGZUUNbidI3k3a+ZqioA3 Mvm/amWKxEIbMxI1gikMYM6qdL06V0GRWNKvKE27ffZZCyixMEJcHLcRNbETlWWQ0qlF oDAFt1RvaHOE0eoaB+e3zlS0GCCKSYtq1zxbSbN0F2h3Vg4V+Iy0ce8qquH/nLN+MY+G RWoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=VTwjD/QtnHowxcoReTOrcSyi+OKYuc4yCl6EvB9JWzs=; b=kjWc1gqEMFk/RLZr98LaLw9YH3N96pu9SJRW+hqPC4qsf4tsHWjGOlIpTyMHPWUtNC F6k87MfjgGVcmoNdQJqPnUZ00qYEG54zFkdEeBmhXc5Q5Sc02FOO+DOTyASHGYQIMWY+ /72wg7JI80eK4uK65z76QEHbxYxXsmGakLI0uTy9Jh8u7OQ4QtpPlPlGuybABzEF9bIG bwQO163TqJN4tAi5bSMo0VGD0p4qNXUCXYJAgcRo83gxt9fCLchtDTqsao7yj9yYgAom tVcfxhL88I8DH+tl+KxqPQPfreZ+ucLxbXkK7EwCSn/0+W2l0xxZV2viMfsYubN9/XUi M+BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TdbvruIf; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s26si8519726wrb.63.2017.12.03.03.19.53; Sun, 03 Dec 2017 03:19:53 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TdbvruIf; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9D20A68A4CA; Sun, 3 Dec 2017 13:19:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D401068A344 for ; Sun, 3 Dec 2017 13:19:41 +0200 (EET) Received: by mail-wr0-f175.google.com with SMTP id x49so14289031wrb.13 for ; Sun, 03 Dec 2017 03:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=N/5EpAM0xIPcAKWi4iHZ+bsTIg0GSNs9KUkTRWAJB38=; b=TdbvruIfYUWb4lToLha//7HMGeTr8WLtNz8M9NML4M8RVMvuJXObIoin4Z5T7jgyih JL/Vr9T0dID4u9GZchRp+asKbcnoWdBh6xI0ojFKfOLEOtQlK/148ne2g3nuOL4m/siR +8BeiZT7QuRwhmAdFzzqCiu3cJe9h/C9cztFRmP4zmsLOIY1Yj7+i2vPuJP42Y4zf1N8 /O4aCgB//BrJbIREGaBX1MqFSFMCdurFTgkZL9SQZp8G7ybi7miYuTFivNxSgEiir2T8 wQE/mdBj+qOMwEOvRGlC8K2FlsuwdW7rVd968yLIX6tZY5cgg1ebEtKsVPo280RvmLiB RWLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=N/5EpAM0xIPcAKWi4iHZ+bsTIg0GSNs9KUkTRWAJB38=; b=Z4W67wwOf+5YCRaCWARurkNgV3/cH+y8RQD7P7kZ42WGgvJAuN8144YTU2GjJC318r zYJRldjK/m9MI2ntu9ueaSWj1yMXqtwmBJwMX4WGgVGu3Fd9F+o+SFmf/RrM18ptK5TX /HwM/iX1TH3r0xStnv51kBsFtHO+Jp/WwI6n8IjgOPUmiKrYY08bcOk1Wzrs+UNQgORO keKPhHnGuY8I6p8PazPxdBfBPGxZoKHDIS3Iw5OAkFX0BaZ1lLPg0cciJMUS9NAC1YSS QuDSVD5oIEB7gFyB0Q4IZUhiAKSgUsYwBezzBMW24ZT/T+bR5dYRm2vELwW223AV4s+9 hJdA== X-Gm-Message-State: AJaThX6tz0FRsxqUI8z2ejqdA86FkmbX5E8yUlr8QhWya7ux7fc7vDfj 8egX4mb3dYzQXHENPw0rBokX5Q== X-Received: by 10.223.188.81 with SMTP id a17mr10655649wrh.146.1512299985439; Sun, 03 Dec 2017 03:19:45 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id l6sm8908009wre.53.2017.12.03.03.19.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Dec 2017 03:19:44 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 3 Dec 2017 12:19:03 +0100 Message-Id: <20171203111903.31447-1-onemda@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avfilter: add setrange filter 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- doc/filters.texi | 31 ++++++++++++++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_setparams.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 libavfilter/vf_setparams.c diff --git a/doc/filters.texi b/doc/filters.texi index f7c371592f..718263a608 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -18496,6 +18496,37 @@ asetpts=N/SR/TB @end itemize +@section setrange + +Force color range for the output video frame. + +The @code{setrange} filter marks the color range property for the +output frames. It does not change the input frame, but only sets the +corresponding property, which affects how the frame is treated by +following filters. + +The filter accepts the following options: + +@table @option + +@item range +Available values are: + +@table @samp +@item auto +Keep the same color range property. + +@item unspecified, unknown +Set the color range as unspecified. + +@item limited, tv, mpeg +Set the color range as limited. + +@item full, pc, jpeg +Set the color range as full. +@end table +@end table + @section settb, asettb Set the timebase to use for the output frames timestamps. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 1c0cc1da80..6b06d57234 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -300,6 +300,7 @@ OBJS-$(CONFIG_SEPARATEFIELDS_FILTER) += vf_separatefields.o OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o OBJS-$(CONFIG_SETFIELD_FILTER) += vf_setfield.o OBJS-$(CONFIG_SETPTS_FILTER) += setpts.o +OBJS-$(CONFIG_SETRANGE_FILTER) += vf_setparams.o OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o OBJS-$(CONFIG_SETTB_FILTER) += settb.o OBJS-$(CONFIG_SHOWINFO_FILTER) += vf_showinfo.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index fc212e58db..707faad777 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -309,6 +309,7 @@ static void register_all(void) REGISTER_FILTER(SETDAR, setdar, vf); REGISTER_FILTER(SETFIELD, setfield, vf); REGISTER_FILTER(SETPTS, setpts, vf); + REGISTER_FILTER(SETRANGE, setrange, vf); REGISTER_FILTER(SETSAR, setsar, vf); REGISTER_FILTER(SETTB, settb, vf); REGISTER_FILTER(SHOWINFO, showinfo, vf); diff --git a/libavfilter/vf_setparams.c b/libavfilter/vf_setparams.c new file mode 100644 index 0000000000..7668bd4cdf --- /dev/null +++ b/libavfilter/vf_setparams.c @@ -0,0 +1,82 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/pixfmt.h" +#include "libavutil/opt.h" +#include "avfilter.h" +#include "internal.h" +#include "video.h" + +typedef struct SetParamsContext { + const AVClass *class; + int color_range; +} SetParamsContext; + +#define OFFSET(x) offsetof(SetParamsContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM + +static const AVOption setrange_options[] = { + {"range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=-1},-1, AVCOL_RANGE_NB-1, FLAGS, "range"}, + {"auto", "keep the same color range", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, FLAGS, "range"}, + {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"}, + {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"}, + {"limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"}, + {"tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"}, + {"mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"}, + {"full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"}, + {"pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"}, + {"jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"}, + {NULL} +}; + +AVFILTER_DEFINE_CLASS(setrange); + +static int filter_frame(AVFilterLink *inlink, AVFrame *frame) +{ + SetParamsContext *s = inlink->dst->priv; + + if (s->color_range >= 0) + frame->color_range = s->color_range; + return ff_filter_frame(inlink->dst->outputs[0], frame); +} + +static const AVFilterPad inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .filter_frame = filter_frame, + }, + { NULL } +}; + +static const AVFilterPad outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + }, + { NULL } +}; + +AVFilter ff_vf_setrange = { + .name = "setrange", + .description = NULL_IF_CONFIG_SMALL("Force color range for the output video frame."), + .priv_size = sizeof(SetParamsContext), + .priv_class = &setrange_class, + .inputs = inputs, + .outputs = outputs, +};