From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 16B5949F75 for ; Fri, 15 Mar 2024 12:22:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D55D268D15D; Fri, 15 Mar 2024 14:22:44 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5060968D0AE for ; Fri, 15 Mar 2024 14:22:38 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1710505358; bh=7te3kXd/t9+uuOeJnMBCLSZcQKGJpluDcbX+8VTwO7Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=X7T8oPhu+8M+e9/N7DXkfS8/3MR9c48sjUc8L++E+MdNrjCgbYLjghNMgryXPSain EDmDuPcSmmJSEm90XUzrdXowpj0Az2rMSoQUXRjlIBdRbQ01R1Mou9wycn6cp0gQSv tM18mq+kERBPkVWheA6eRIe0GbYc2DEPerZ8plHs= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 1F02F40247; Fri, 15 Mar 2024 13:22:38 +0100 (CET) Date: Fri, 15 Mar 2024 13:22:37 +0100 Message-ID: <20240315132237.GB76907@haasn.xyz> From: Niklas Haas To: ffmpeg-devel@ffmpeg.org In-Reply-To: <20240315120442.73754-6-ffmpeg@haasn.xyz> References: <20240315120442.73754-1-ffmpeg@haasn.xyz> <20240315120442.73754-6-ffmpeg@haasn.xyz> MIME-Version: 1.0 Content-Disposition: inline Subject: Re: [FFmpeg-devel] [PATCH v3 5/9] avutil/film_grain_params: add av_film_grain_params_select() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Fri, 15 Mar 2024 12:58:58 +0100 Niklas Haas wrote: > From: Niklas Haas > > Common utility function that can be used by all codecs to select the > right (any valid) film grain parameter set. In particular, this is > useful for AFGS1, which has support for multiple parameters. > > However, it also performs parameter validation for H274. > --- > doc/APIchanges | 3 ++ > libavutil/film_grain_params.c | 57 +++++++++++++++++++++++++++++++++++ > libavutil/film_grain_params.h | 7 +++++ > libavutil/version.h | 2 +- > 4 files changed, 68 insertions(+), 1 deletion(-) > > diff --git a/doc/APIchanges b/doc/APIchanges > index 5a192b600af..34245c8b708 100644 > --- a/doc/APIchanges > +++ b/doc/APIchanges > @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07 > > API changes, most recent first: > > +2024-03-08 - xxxxxxxxxx - lavu 59.3.100 - film_grain_params.h > + Add av_film_grain_params_select(). > + > 2024-03-08 - xxxxxxxxxx - lavu 59.2.100 - film_grain_params.h > Add AVFilmGrainAOMParams.color_range, color_primaries, color_trc, > color_space, width, height, subx, suby and bit_depth. > diff --git a/libavutil/film_grain_params.c b/libavutil/film_grain_params.c > index 930d23c7fe9..8c80adc66a7 100644 > --- a/libavutil/film_grain_params.c > +++ b/libavutil/film_grain_params.c > @@ -17,6 +17,7 @@ > */ > > #include "film_grain_params.h" > +#include "pixdesc.h" > > AVFilmGrainParams *av_film_grain_params_alloc(size_t *size) > { > @@ -40,3 +41,59 @@ AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame) > > return (AVFilmGrainParams *)side_data->data; > } > + > +const AVFilmGrainParams *av_film_grain_params_select(const AVFrame *frame) > +{ > + const AVFilmGrainParams *fgp, *best = NULL; > + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); > + const AVFilmGrainAOMParams *aom; > + const AVFilmGrainH274Params *h274; > + if (!desc) > + return NULL; > + > +#define CHECK(a, b, unspec) \ > + do { \ > + if ((a) != (unspec) && (b) != (unspec) && (a) != (b)) \ > + continue; \ > + } while (0) > + > + for (int i = 0; i < frame->nb_side_data; i++) { > + if (frame->side_data[i]->type != AV_FRAME_DATA_FILM_GRAIN_PARAMS) > + continue; > + fgp = (const AVFilmGrainParams*)frame->side_data[i]->data; > + switch (fgp->type) { > + case AV_FILM_GRAIN_PARAMS_NONE: > + continue; > + case AV_FILM_GRAIN_PARAMS_AV1: > + aom = &fgp->codec.aom; > + if (aom->subx != desc->log2_chroma_w || aom->suby != desc->log2_chroma_h) > + continue; > + CHECK(aom->bit_depth, desc->comp[0].depth, 0); > + CHECK(aom->width, frame->width, 0); > + CHECK(aom->height, frame->height, 0); This condition is wrong, it should allow all aom->width <= frame->width; not just an exact match. > + CHECK(aom->color_range, frame->color_range, AVCOL_RANGE_UNSPECIFIED); > + CHECK(aom->color_primaries, frame->color_primaries, AVCOL_PRI_UNSPECIFIED); > + CHECK(aom->color_trc, frame->color_trc, AVCOL_TRC_UNSPECIFIED); > + CHECK(aom->color_space, frame->colorspace, AVCOL_SPC_UNSPECIFIED); > + > + if (!best || > + best->codec.aom.width < aom->width || > + best->codec.aom.height < aom->height) > + best = fgp; > + break; > + case AV_FILM_GRAIN_PARAMS_H274: > + h274 = &fgp->codec.h274; > + /* There are no YUV formats with different bit depth per component, > + * so just check both against the first component for simplicity */ > + CHECK(h274->bit_depth_luma, desc->comp[0].depth, 0); > + CHECK(h274->bit_depth_chroma, desc->comp[0].depth, 0); > + CHECK(h274->color_range, frame->color_range, AVCOL_RANGE_UNSPECIFIED); > + CHECK(h274->color_primaries, frame->color_primaries, AVCOL_PRI_UNSPECIFIED); > + CHECK(h274->color_trc, frame->color_trc, AVCOL_TRC_UNSPECIFIED); > + CHECK(h274->color_space, frame->colorspace, AVCOL_SPC_UNSPECIFIED); > + return fgp; /* H274 can't have multiple resolutions */ > + } > + } > + > + return best; > +} > diff --git a/libavutil/film_grain_params.h b/libavutil/film_grain_params.h > index 17fefeb06c3..75c020ceb92 100644 > --- a/libavutil/film_grain_params.h > +++ b/libavutil/film_grain_params.h > @@ -272,4 +272,11 @@ AVFilmGrainParams *av_film_grain_params_alloc(size_t *size); > */ > AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame); > > +/** > + * Select the most appropriate film grain parameters set for the frame, > + * taking into account the frame's format, resolution and video signal > + * characteristics. > + */ > +const AVFilmGrainParams *av_film_grain_params_select(const AVFrame *frame); > + > #endif /* AVUTIL_FILM_GRAIN_PARAMS_H */ > diff --git a/libavutil/version.h b/libavutil/version.h > index 57cad02ec0a..5027b025be4 100644 > --- a/libavutil/version.h > +++ b/libavutil/version.h > @@ -79,7 +79,7 @@ > */ > > #define LIBAVUTIL_VERSION_MAJOR 59 > -#define LIBAVUTIL_VERSION_MINOR 2 > +#define LIBAVUTIL_VERSION_MINOR 3 > #define LIBAVUTIL_VERSION_MICRO 100 > > #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ > -- > 2.44.0 > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".