FFmpeg
Loading...
Searching...
No Matches
film_grain_params.c
Go to the documentation of this file.
1/**
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "film_grain_params.h"
20#include "mem.h"
21#include "pixdesc.h"
22
24{
26
27 if (size)
28 *size = params ? sizeof(*params) : 0;
29
30 return params;
31}
32
34{
38 sizeof(AVFilmGrainParams));
39 if (!side_data)
40 return NULL;
41
42 fgp = (AVFilmGrainParams *) side_data->data;
43 *fgp = (AVFilmGrainParams) {
44 .color_range = AVCOL_RANGE_UNSPECIFIED,
45 .color_primaries = AVCOL_PRI_UNSPECIFIED,
46 .color_trc = AVCOL_TRC_UNSPECIFIED,
47 .color_space = AVCOL_SPC_UNSPECIFIED,
48 };
49
50 return fgp;
51}
52
54{
55 const AVFilmGrainParams *fgp, *best = NULL;
57 int bit_depth_luma, bit_depth_chroma;
58 if (!desc)
59 return NULL;
60
61 /* There are no YUV formats with different bit depth per component,
62 * so just check both against the first component for simplicity */
63 bit_depth_luma = bit_depth_chroma = desc->comp[0].depth;
64
65 for (int i = 0; i < frame->nb_side_data; i++) {
66 if (frame->side_data[i]->type != AV_FRAME_DATA_FILM_GRAIN_PARAMS)
67 continue;
68 fgp = (const AVFilmGrainParams*)frame->side_data[i]->data;
69 if (fgp->width && fgp->width > frame->width ||
70 fgp->height && fgp->height > frame->height)
71 continue;
72
73#define CHECK(a, b, unspec) \
74 if ((a) != (unspec) && (b) != (unspec) && (a) != (b)) \
75 continue
76
77 CHECK(fgp->bit_depth_luma, bit_depth_luma, 0);
78 CHECK(fgp->bit_depth_chroma, bit_depth_chroma, 0);
80 CHECK(fgp->color_primaries, frame->color_primaries, AVCOL_PRI_UNSPECIFIED);
81 CHECK(fgp->color_trc, frame->color_trc, AVCOL_TRC_UNSPECIFIED);
82 CHECK(fgp->color_space, frame->colorspace, AVCOL_SPC_UNSPECIFIED);
83
84 switch (fgp->type) {
86 continue;
88 /* AOM FGS needs an exact match for the chroma resolution */
89 if (fgp->subsampling_x != desc->log2_chroma_w ||
90 fgp->subsampling_y != desc->log2_chroma_h)
91 continue;
92 break;
94 /* H.274 FGS can be adapted to any lower chroma resolution */
95 if (fgp->subsampling_x > desc->log2_chroma_w ||
96 fgp->subsampling_y > desc->log2_chroma_h)
97 continue;
98 break;
99 }
100
101 if (!best || best->width < fgp->width || best->height < fgp->height)
102 best = fgp;
103 }
104
105 return best;
106}
SwsAArch64OpImplParams params
Definition ops.c:51
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
static AVFrame * frame
#define CHECK(a, b, unspec)
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
const AVFilmGrainParams * av_film_grain_params_select(const AVFrame *frame)
Select the most appropriate film grain parameters set for the frame, taking into account the frame's ...
AVFilmGrainParams * av_film_grain_params_alloc(size_t *size)
This file is part of FFmpeg.
@ AV_FILM_GRAIN_PARAMS_H274
The union is valid when interpreted as AVFilmGrainH274Params (codec.h274)
@ AV_FILM_GRAIN_PARAMS_AV1
The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
@ AV_FILM_GRAIN_PARAMS_NONE
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
Definition frame.c:647
@ AV_FRAME_DATA_FILM_GRAIN_PARAMS
Film grain parameters for a frame, described by AVFilmGrainParams.
Definition frame.h:188
const char * desc
Definition libsvtav1.c:83
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:645
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:675
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
This structure describes how to handle film grain synthesis in video for specific codecs.
enum AVColorPrimaries color_primaries
enum AVColorRange color_range
Intended video signal characteristics.
int subsampling_x
Intended subsampling ratio, or 0 for luma-only streams.
int bit_depth_luma
Intended bit depth, or 0 for unknown/unspecified.
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
int width
Intended display resolution.
enum AVColorTransferCharacteristic color_trc
enum AVColorSpace color_space
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
#define av_mallocz(s)
int size