FFmpeg: libavfilter/vf_qp.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <math.h>
25
29
37
38 static const char *
const var_names[] = {
"known",
"qp",
"x",
"y",
"w",
"h",
NULL };
39
40 #define OFFSET(x) offsetof(QPContext, x)
41 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
42
46 };
47
49
51 {
57
59 return 0;
60
64
66 s->qstride = (
inlink->w + 15) >> 4;
67 for (
i = -129;
i < 128;
i++) {
68 double var_values[] = {
i != -129,
i,
NAN,
NAN,
s->qstride,
s->h, 0};
70
71 if (
isnan(temp_val)) {
72 if(strchr(
s->qp_expr_str,
'x') || strchr(
s->qp_expr_str,
'y'))
73 s->evaluate_per_mb = 1;
74 else {
77 }
78 }
79
81 }
83
84 return 0;
85 }
86
88 {
94
97 int8_t in_qp_global = 0;
98
100
101 if (!
s->qp_expr_str ||
ctx->is_disabled)
103
107
108 // we accept the input QP table only if it is of the MPEG2 type
109 // and contains either no blocks at all or 16x16 macroblocks
112 in_qp_global = par_in->
qp;
115 } else
117 }
118
123 }
124
126 (
s->evaluate_per_mb || sd_in) ?
127 s->h *
s->qstride : 0);
128 if (!par_out) {
131 }
132
133 #define BLOCK_QP_DELTA(block_idx) \
134 (par_in ? av_video_enc_params_block(par_in, block_idx)->delta_qp : 0)
135
136 if (
s->evaluate_per_mb) {
137 int y, x;
138
139 for (y = 0; y <
s->h; y++)
140 for (x = 0; x <
s->qstride; x++) {
141 unsigned int block_idx = y *
s->qstride + x;
144 double var_values[] = { !!sd_in, qp, x, y,
s->qstride,
s->h, 0};
145 double temp_val;
146
152 b->delta_qp =
lrintf(temp_val);
153 }
154 } else if (sd_in) {
155 int y, x;
156
157 for (y = 0; y <
s->h; y++)
158 for (x = 0; x <
s->qstride; x++) {
159 unsigned int block_idx = y *
s->qstride + x;
161 b->delta_qp =
s->lut[129 + (int8_t)(in_qp_global +
BLOCK_QP_DELTA(block_idx))];
162 }
163 } else {
164 par_out->
qp =
s->lut[0];
165 }
166
173 }
174
176 {
181 },
182 };
183
187 .p.priv_class = &qp_class,
193 };
int32_t qp
Base quantisation parameter for the frame.
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static const char *const var_names[]
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
A link between two filters.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
@ AV_VIDEO_ENC_PARAMS_MPEG2
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Video encoding parameters for a given frame.
A filter pad used for either input or output.
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
enum AVVideoEncParamsType type
Type of the parameters (the codec they are used with).
#define FILTER_OUTPUTS(array)
Describe the class of an AVClass context structure.
static int config_input(AVFilterLink *inlink)
AVVideoEncParams * av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type, unsigned int nb_blocks)
Allocates memory for AVEncodeInfoFrame plus an array of.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
unsigned int nb_blocks
Number of blocks in the array.
#define i(width, name, range_min, range_max)
Data structure for storing block-level encoding information.
const char * name
Pad name.
@ AV_FRAME_DATA_VIDEO_ENC_PARAMS
Encoding parameters for a video frame, as described by AVVideoEncParams.
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
AVFilter p
The public AVFilter.
Structure to hold side data for an AVFrame.
static const AVOption qp_options[]
static const AVFilterPad qp_inputs[]
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define BLOCK_QP_DELTA(block_idx)
static av_always_inline AVVideoBlockParams * av_video_enc_params_block(AVVideoEncParams *par, unsigned int idx)
Get the block at the specified.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
AVFILTER_DEFINE_CLASS(qp)
Generated on Tue Nov 18 2025 19:23:16 for FFmpeg by
doxygen
1.8.17