History

libavutil: introduce AVFilmGrainParams side data

This patch introduces a new frame side data type AVFilmGrainParams for use with video codecs which support it. It can save a lot of memory used for duplicate processed reference frames and reduce copies when applying film grain during presentation.

Lynne committed 6 years ago

Commit 4f9ee871 parent 5b1ccd77 files · +223 −1Browse files

Unified · Split

7 files
  1. doc/APIchanges +4 −0
  2. libavutil/Makefile +2 −0
  3. libavutil/film_grain_params.c +42 −0
  4. libavutil/film_grain_params.h +167 −0
  5. libavutil/frame.c +1 −0
  6. libavutil/frame.h +6 −0
  7. libavutil/version.h +1 −1
doc/APIchanges+4−0
@@ -15,6 +15,10 @@ libavutil: 2017-10-21 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182020-11-25 - xxxxxxxxxx - lavu 56.61.100 - film_grain_params.h
19 Adds a new API for extracting codec film grain parameters as side data.
20 Adds a new AVFrameSideDataType entry AV_FRAME_DATA_FILM_GRAIN_PARAMS for it.
21
182020-xx-xx - xxxxxxxxxx - lavf 58.64.100 - avformat.h222020-xx-xx - xxxxxxxxxx - lavf 58.64.100 - avformat.h
19 Add AVSTREAM_EVENT_FLAG_NEW_PACKETS.23 Add AVSTREAM_EVENT_FLAG_NEW_PACKETS.
20 24
libavutil/Makefile+2−0
@@ -84,6 +84,7 @@ HEADERS = adler32.h \ · 83 unmodified lines
84 xtea.h \84 xtea.h \
85 tea.h \85 tea.h \
86 tx.h \86 tx.h \
87 film_grain_params.h \
87 88
88HEADERS-$(CONFIG_LZO) += lzo.h89HEADERS-$(CONFIG_LZO) += lzo.h
89 90
@@ -170,6 +171,7 @@ OBJS = adler32.o \ · 80 unmodified lines
170 tx_double.o \171 tx_double.o \
171 tx_int32.o \172 tx_int32.o \
172 video_enc_params.o \173 video_enc_params.o \
174 film_grain_params.o \
173 175
174 176
175OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o177OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
libavutil/film_grain_params.c+42−0
@@ -0,0 +1,42 @@
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
21AVFilmGrainParams *av_film_grain_params_alloc(size_t *size)
22{
23 AVFilmGrainParams *params = av_mallocz(sizeof(AVFilmGrainParams));
24
25 if (size)
26 *size = sizeof(*params);
27
28 return params;
29}
30
31AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame)
32{
33 AVFrameSideData *side_data = av_frame_new_side_data(frame,
34 AV_FRAME_DATA_FILM_GRAIN_PARAMS,
35 sizeof(AVFilmGrainParams));
36 if (!side_data)
37 return NULL;
38
39 memset(side_data->data, 0, sizeof(AVFilmGrainParams));
40
41 return (AVFilmGrainParams *)side_data->data;
42}
libavutil/film_grain_params.h+167−0
@@ -0,0 +1,167 @@
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#ifndef AVUTIL_FILM_GRAIN_PARAMS_H
20#define AVUTIL_FILM_GRAIN_PARAMS_H
21
22#include "frame.h"
23
24enum AVFilmGrainParamsType {
25 AV_FILM_GRAM_PARAMS_NONE = 0,
26
27 /**
28 * The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
29 */
30 AV_FILM_GRAM_PARAMS_AV1,
31};
32
33/**
34 * This structure describes how to handle film grain synthesis for AOM codecs.
35 *
36 * @note The struct must be allocated as part of AVFilmGrainParams using
37 * av_film_grain_params_alloc(). Its size is not a part of the public ABI.
38 */
39typedef struct AVFilmGrainAOMParams {
40 /**
41 * Number of points, and the scale and value for each point of the
42 * piecewise linear scaling function for the uma plane.
43 */
44 int num_y_points;
45 uint8_t y_points[14][2 /* value, scaling */];
46
47 /**
48 * Signals whether to derive the chroma scaling function from the luma.
49 * Not equivalent to copying the luma values and scales.
50 */
51 int chroma_scaling_from_luma;
52
53 /**
54 * If chroma_scaling_from_luma is set to 0, signals the chroma scaling
55 * function parameters.
56 */
57 int num_uv_points[2];
58 uint8_t uv_points[2][10][2 /* value, scaling */];
59
60 /**
61 * Specifies the shift applied to the chroma components. For AV1, its within
62 * [8; 11] and determines the range and quantization of the film grain.
63 */
64 int scaling_shift;
65
66 /**
67 * Specifies the auto-regression lag. The number of coefficients is given by
68 * 2*ar_coeff_lag(ar_coeff_lag - 1), with an extra one for the chroma.
69 */
70 int ar_coeff_lag;
71
72 /**
73 * Luma auto-regression coefficients.
74 */
75 int8_t ar_coeffs_y[24];
76
77 /**
78 * Chroma auto-regression coefficients.
79 */
80 int8_t ar_coeffs_uv[2][25];
81
82 /**
83 * Specifies the range of the auto-regressive coefficients. Values of 6,
84 * 7, 8 and so on represent a range of [-2, 2), [-1, 1), [-0.5, 0.5) and
85 * so on. For AV1 must be between 6 and 9.
86 */
87 int ar_coeff_shift;
88
89 /**
90 * Signals the down shift applied to the generated gaussian numbers during
91 * synthesis.
92 */
93 int grain_scale_shift;
94
95 /**
96 * Specifies the luma/chroma multipliers for the index to the component
97 * scaling function.
98 */
99 int uv_mult[2];
100 int uv_mult_luma[2];
101
102 /**
103 * Offset used for component scaling function. For AV1 its a 9-bit value
104 * with a range [-256, 255]
105 */
106 int uv_offset[2];
107
108 /**
109 * Signals whether to overlap film grain blocks.
110 */
111 int overlap_flag;
112
113 /**
114 * Signals to clip to limited color levels after film grain application.
115 */
116 int limit_output_range;
117} AVFilmGrainAOMParams;
118
119/**
120 * This structure describes how to handle film grain synthesis in video
121 * for specific codecs. Must be present on every frame where film grain is
122 * meant to be synthesised for correct presentation.
123 *
124 * @note The struct must be allocated with av_film_grain_params_alloc() and
125 * its size is not a part of the public ABI.
126 */
127typedef struct AVFilmGrainParams {
128 /**
129 * Specifies the codec for which this structure is valid.
130 */
131 enum AVFilmGrainParamsType type;
132
133 /**
134 * Seed to use for the synthesis process, if the codec allows for it.
135 */
136 uint64_t seed;
137
138 /**
139 * Additional fields may be added both here and in any structure included.
140 * If a codec's film grain structure differs slightly over another
141 * codec's, fields within may change meaning depending on the type.
142 */
143 union {
144 AVFilmGrainAOMParams aom;
145 } codec;
146} AVFilmGrainParams;
147
148/**
149 * Allocate an AVFilmGrainParams structure and set its fields to
150 * default values. The resulting struct can be freed using av_freep().
151 * If size is not NULL it will be set to the number of bytes allocated.
152 *
153 * @return An AVFilmGrainParams filled with default values or NULL
154 * on failure.
155 */
156AVFilmGrainParams *av_film_grain_params_alloc(size_t *size);
157
158/**
159 * Allocate a complete AVFilmGrainParams and add it to the frame.
160 *
161 * @param frame The frame which side data is added to.
162 *
163 * @return The AVFilmGrainParams structure to be filled by caller.
164 */
165AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame);
166
167#endif /* AVUTIL_FILM_GRAIN_PARAMS_H */
libavutil/frame.c+1−0
@@ -851,6 +851,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type) · 850 unmodified lines
851 case AV_FRAME_DATA_REGIONS_OF_INTEREST: return "Regions Of Interest";851 case AV_FRAME_DATA_REGIONS_OF_INTEREST: return "Regions Of Interest";
852 case AV_FRAME_DATA_VIDEO_ENC_PARAMS: return "Video encoding parameters";852 case AV_FRAME_DATA_VIDEO_ENC_PARAMS: return "Video encoding parameters";
853 case AV_FRAME_DATA_SEI_UNREGISTERED: return "H.26[45] User Data Unregistered SEI message";853 case AV_FRAME_DATA_SEI_UNREGISTERED: return "H.26[45] User Data Unregistered SEI message";
854 case AV_FRAME_DATA_FILM_GRAIN_PARAMS: return "Film grain parameters";
854 }855 }
855 return NULL;856 return NULL;
856}857}
libavutil/frame.h+6−0
@@ -192,6 +192,12 @@ enum AVFrameSideDataType { · 191 unmodified lines
192 * uuid_iso_iec_11578 followed by AVFrameSideData.size - 16 bytes of user_data_payload_byte.192 * uuid_iso_iec_11578 followed by AVFrameSideData.size - 16 bytes of user_data_payload_byte.
193 */193 */
194 AV_FRAME_DATA_SEI_UNREGISTERED,194 AV_FRAME_DATA_SEI_UNREGISTERED,
195
196 /**
197 * Film grain parameters for a frame, described by AVFilmGrainParameters.
198 * Must be present for every frame which should have film grain applied.
199 */
200 AV_FRAME_DATA_FILM_GRAIN_PARAMS,
195};201};
196 202
197enum AVActiveFormatDescription {203enum AVActiveFormatDescription {
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
79 */79 */
80 80
81#define LIBAVUTIL_VERSION_MAJOR 5681#define LIBAVUTIL_VERSION_MAJOR 56
82#define LIBAVUTIL_VERSION_MINOR 6082#define LIBAVUTIL_VERSION_MINOR 61
83#define LIBAVUTIL_VERSION_MICRO 10083#define LIBAVUTIL_VERSION_MICRO 100
84 84
85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t