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 <stdio.h>
20
22#include "libavutil/mem.h"
23
25{
27 if (!frame)
28 return NULL;
29 frame->format = format;
30 frame->width = width;
31 frame->height = height;
32 return frame;
33}
34
37 int width, int height,
38 int sub_x, int sub_y,
39 int bd_luma, int bd_chroma)
40{
42 if (!fgp)
43 return NULL;
44 fgp->type = type;
45 fgp->width = width;
46 fgp->height = height;
47 fgp->subsampling_x = sub_x;
48 fgp->subsampling_y = sub_y;
49 fgp->bit_depth_luma = bd_luma;
50 fgp->bit_depth_chroma = bd_chroma;
51 return fgp;
52}
53
54int main(void)
55{
57 const AVFilmGrainParams *sel;
59 size_t size;
60
61 printf("Testing av_film_grain_params_alloc()\n");
62
64 printf("alloc with size: %s\n", (fgp && size > 0) ? "OK" : "FAIL");
65 av_free(fgp);
66
68 printf("alloc without size: %s\n", fgp ? "OK" : "FAIL");
69 av_free(fgp);
70
71 printf("\nTesting av_film_grain_params_create_side_data()\n");
72
75 if (fgp)
76 printf("create: OK\ndefaults: range=%d pri=%d trc=%d space=%d\n",
78 fgp->color_trc, fgp->color_space);
79 else
80 printf("create: FAIL\n");
82
83 printf("\nTesting av_film_grain_params_select()\n");
84
85 /* invalid format */
87 frame->format = -1;
89 printf("invalid format: %s\n", sel ? "FAIL" : "NULL");
91
92 /* no side data */
95 printf("no side data: %s\n", sel ? "FAIL" : "NULL");
97
98 /* NONE type - skipped */
100 add_grain(frame, AV_FILM_GRAIN_PARAMS_NONE, 0, 0, 1, 1, 0, 0);
102 printf("NONE type: %s\n", sel ? "FAIL" : "NULL");
104
105 /* AV1 exact subsampling match (YUV420P: sub 1,1) */
107 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 0);
109 printf("AV1 match: %s\n", sel ? "OK" : "FAIL");
111
112 /* AV1 subsampling mismatch */
114 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 0, 0, 0, 0);
116 printf("AV1 sub mismatch: %s\n", sel ? "FAIL" : "NULL");
118
119 /* H274 exact match */
121 add_grain(frame, AV_FILM_GRAIN_PARAMS_H274, 0, 0, 1, 1, 0, 0);
123 printf("H274 match: %s\n", sel ? "OK" : "FAIL");
125
126 /* H274 lower subsampling OK (grain sub 0,0 < YUV420P sub 1,1) */
128 add_grain(frame, AV_FILM_GRAIN_PARAMS_H274, 0, 0, 0, 0, 0, 0);
130 printf("H274 lower sub: %s\n", sel ? "OK" : "FAIL");
132
133 /* H274 higher subsampling FAIL (grain sub 1,1 > YUV444P sub 0,0) */
135 add_grain(frame, AV_FILM_GRAIN_PARAMS_H274, 0, 0, 1, 1, 0, 0);
137 printf("H274 higher sub: %s\n", sel ? "FAIL" : "NULL");
139
140 /* width too large */
142 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 3840, 0, 1, 1, 0, 0);
144 printf("width too large: %s\n", sel ? "FAIL" : "NULL");
146
147 /* height too large */
149 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 2160, 1, 1, 0, 0);
151 printf("height too large: %s\n", sel ? "FAIL" : "NULL");
153
154 /* width/height = 0 (unspecified) - passes */
156 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 0);
158 printf("size unspecified: %s\n", sel ? "OK" : "FAIL");
160
161 /* bit_depth_luma mismatch (grain=10, YUV420P=8) */
163 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 10, 0);
165 printf("bd_luma mismatch: %s\n", sel ? "FAIL" : "NULL");
167
168 /* bit_depth_chroma mismatch (grain=10, YUV420P=8) */
170 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 10);
172 printf("bd_chroma mismatch: %s\n", sel ? "FAIL" : "NULL");
174
175 /* bit_depth = 0 (unspecified) - passes */
177 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 0);
179 printf("bd unspecified: %s\n", sel ? "OK" : "FAIL");
181
182 /* bit_depth exact match (grain=8, YUV420P=8) */
184 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 8, 8);
186 printf("bd exact match: %s\n", sel ? "OK" : "FAIL");
188
189 /* color_range mismatch */
191 frame->color_range = AVCOL_RANGE_MPEG;
192 fgp = add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 0);
195 printf("color_range mismatch: %s\n", sel ? "FAIL" : "NULL");
197
198 /* color_primaries mismatch */
200 frame->color_primaries = AVCOL_PRI_BT709;
201 fgp = add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 0);
204 printf("color_primaries mismatch: %s\n", sel ? "FAIL" : "NULL");
206
207 /* color_trc mismatch */
209 frame->color_trc = AVCOL_TRC_BT709;
210 fgp = add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 0);
213 printf("color_trc mismatch: %s\n", sel ? "FAIL" : "NULL");
215
216 /* color_space mismatch */
218 frame->colorspace = AVCOL_SPC_BT709;
219 fgp = add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 0);
222 printf("color_space mismatch: %s\n", sel ? "FAIL" : "NULL");
224
225 /* color properties UNSPECIFIED - passes */
227 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 0, 0, 1, 1, 0, 0);
229 printf("color unspecified: %s\n", sel ? "OK" : "FAIL");
231
232 /* multiple entries - best selection by size */
234 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 640, 480, 1, 1, 0, 0);
235 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 1280, 720, 1, 1, 0, 0);
236 add_grain(frame, AV_FILM_GRAIN_PARAMS_AV1, 1000, 1080, 1, 1, 0, 0);
238 printf("best selection: width=%d height=%d\n",
239 sel ? sel->width : -1, sel ? sel->height : -1);
241
242 return 0;
243}
static const char *const format[]
Definition af_aiir.c:444
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
static AVFrame * frame
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.
AVFilmGrainParamsType
@ 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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
cl_device_type type
Memory handling functions.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition pixfmt.h:644
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition pixfmt.h:647
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:677
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition pixfmt.h:674
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:708
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition pixfmt.h:712
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
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
#define av_free(p)
static AVFrame * create_frame(enum AVPixelFormat format, int width, int height)
int main(void)
static AVFilmGrainParams * add_grain(AVFrame *frame, enum AVFilmGrainParamsType type, int width, int height, int sub_x, int sub_y, int bd_luma, int bd_chroma)
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
int size