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 #include <string.h>
19
24
29
30 // ProcAmp Min/Max/Default Values
31 #define BRIGHTNESS_MIN -100.0F
32 #define BRIGHTNESS_MAX 100.0F
33 #define BRIGHTNESS_DEFAULT 0.0F
34
35 #define CONTRAST_MIN 0.0F
36 #define CONTRAST_MAX 10.0F
37 #define CONTRAST_DEFAULT 1.0F
38
39 #define HUE_MIN -180.0F
40 #define HUE_MAX 180.0F
41 #define HUE_DEFAULT 0.0F
42
43 #define SATURATION_MIN 0.0F
44 #define SATURATION_MAX 10.0F
45 #define SATURATION_DEFAULT 1.0F
46
49
55
56 static float map(
float x,
float in_min,
float in_max,
float out_min,
float out_max)
57 {
58 double slope, output;
59
60 slope = 1.0 * (out_max - out_min) / (in_max - in_min);
61 output = out_min + slope * (x - in_min);
62
63 return (float)output;
64 }
65
67 {
70 VAStatus vas;
71 VAProcFilterParameterBufferColorBalance procamp_params[4];
72 VAProcFilterCapColorBalance procamp_caps[VAProcColorBalanceCount];
73 int num_caps;
74 int i = 0;
75
76 memset(&procamp_params, 0, sizeof(procamp_params));
77 memset(&procamp_caps, 0, sizeof(procamp_caps));
78
79 num_caps = VAProcColorBalanceCount;
81 VAProcFilterColorBalance, &procamp_caps, &num_caps);
82
83 if (vas != VA_STATUS_SUCCESS) {
85 "filter caps: %d (%s).\n", vas, vaErrorStr(vas));
87 }
88
89 /* brightness */
90 procamp_params[i].type = VAProcFilterColorBalance;
91 procamp_params[i].attrib = VAProcColorBalanceBrightness;
93 procamp_caps[VAProcColorBalanceBrightness-1].range.min_value,
94 procamp_caps[VAProcColorBalanceBrightness-1].range.max_value);
95 i++;
96
97 /* contrast */
98 procamp_params[i].type = VAProcFilterColorBalance;
99 procamp_params[i].attrib = VAProcColorBalanceContrast;
101 procamp_caps[VAProcColorBalanceContrast-1].range.min_value,
102 procamp_caps[VAProcColorBalanceContrast-1].range.max_value);
103 i++;
104
105 /* hue */
106 procamp_params[i].type = VAProcFilterColorBalance;
107 procamp_params[i].attrib = VAProcColorBalanceHue;
109 procamp_caps[VAProcColorBalanceHue-1].range.min_value,
110 procamp_caps[VAProcColorBalanceHue-1].range.max_value);
111 i++;
112
113 /* saturation */
114 procamp_params[i].type = VAProcFilterColorBalance;
115 procamp_params[i].attrib = VAProcColorBalanceSaturation;
117 procamp_caps[VAProcColorBalanceSaturation-1].range.min_value,
118 procamp_caps[VAProcColorBalanceSaturation-1].range.max_value);
119 i++;
120
122 VAProcFilterParameterBufferType,
123 &procamp_params,
124 sizeof(procamp_params[0]),
125 i);
126 }
127
129 {
134 VASurfaceID input_surface, output_surface;
135 VAProcPipelineParameterBuffer
params;
136 VARectangle input_region;
137 int err;
138
142
145
146 input_surface = (VASurfaceID)(uintptr_t)input_frame->
data[3];
148 input_surface);
149
152 if (!output_frame) {
155 }
156
157 output_surface = (VASurfaceID)(uintptr_t)output_frame->
data[3];
159 output_surface);
160 memset(¶ms, 0, sizeof(params));
161 input_region = (VARectangle) {
162 .x = 0,
163 .y = 0,
164 .width = input_frame->
width,
165 .height = input_frame->
height,
166 };
167
168 params.surface = input_surface;
169 params.surface_region = &input_region;
170 params.surface_color_standard =
172
173 params.output_region =
NULL;
174 params.output_background_color = 0xff000000;
175 params.output_color_standard = params.surface_color_standard;
176
177 params.pipeline_flags = 0;
178 params.filter_flags = VA_FRAME_PICTURE;
179
181 params.num_filters = 1;
182
184 if (err < 0)
186
188 if (err < 0)
191
195
197
201 return err;
202 }
203
205 {
207
212
213 return 0;
214 }
215
216 #define OFFSET(x) offsetof(ProcampVAAPIContext, x)
217 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
219 { "b", "Output video brightness",
221 { "brightness", "Output video brightness",
223 { "s", "Output video saturation",
225 { "saturatio", "Output video saturation",
227 { "c", "Output video contrast",
229 { "contrast", "Output video contrast",
231 { "h", "Output video hue",
233 { "hue", "Output video hue",
236 };
237
239
241 {
246 },
248 };
249
251 {
255 },
257 };
258
260 .
name =
"procamp_vaapi",
261 .description =
NULL_IF_CONFIG_SMALL(
"ProcAmp (color balance) adjustments for hue, saturation, brightness, contrast"),
266 .
inputs = procamp_vaapi_inputs,
267 .
outputs = procamp_vaapi_outputs,
268 .priv_class = &procamp_vaapi_class,
270 };
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
This structure describes decoded (raw) audio or video data.
int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
int(* build_filter_params)(AVFilterContext *avctx)
Main libavfilter public API header.
Memory handling functions.
int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
static av_cold int init(AVCodecContext *avctx)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int procamp_vaapi_build_filter_params(AVFilterContext *avctx)
static av_cold int uninit(AVCodecContext *avctx)
void(* pipeline_uninit)(AVFilterContext *avctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static float map(float x, float in_min, float in_max, float out_min, float out_max)
int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, VASurfaceID output_surface)
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int procamp_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVColorSpace colorspace
YUV colorspace type.
simple assert() macros that are a bit more flexible than ISO C assert().
static av_cold int procamp_vaapi_init(AVFilterContext *avctx)
#define BRIGHTNESS_DEFAULT
int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, int type, const void *data, size_t size, int count)
AVFilter ff_vf_procamp_vaapi
static const AVOption procamp_vaapi_options[]
void ff_vaapi_vpp_pipeline_uninit(AVFilterContext *avctx)
static const AVFilterPad procamp_vaapi_outputs[]
AVFILTER_DEFINE_CLASS(procamp_vaapi)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
VADisplay display
The VADisplay handle, to be filled by the user.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
VABufferID filter_buffers[VAProcFilterCount]
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
enum AVPixelFormat output_format
AVVAAPIDeviceContext * hwctx
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define SATURATION_DEFAULT
int ff_vaapi_vpp_query_formats(AVFilterContext *avctx)
static int query_formats(AVFilterContext *ctx)
void ff_vaapi_vpp_ctx_init(AVFilterContext *avctx)
static const AVFilterPad procamp_vaapi_inputs[]
int ff_vaapi_vpp_colour_standard(enum AVColorSpace av_cs)
AVFilterContext * dst
dest filter
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
void ff_vaapi_vpp_ctx_uninit(AVFilterContext *avctx)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.