FFmpeg: libavfilter/af_volume.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) 2011 Stefano Sabatini
3 * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * audio volume filter
25 */
26
35
41
43 "fixed", "float", "double"
44 };
45
47 "n", ///< frame number (starting at zero)
48 "nb_channels", ///< number of channels
49 "nb_consumed_samples", ///< number of samples consumed by the filter
50 "nb_samples", ///< number of samples in the current frame
51 #if FF_API_FRAME_PKT
52 "pos", ///< position in the file of the frame
53 #endif
54 "pts", ///< frame presentation timestamp
55 "sample_rate", ///< sample rate
56 "startpts", ///< PTS at start of stream
57 "startt", ///< time at start of stream
58 "t", ///< time in the file of the frame
59 "tb", ///< timebase
60 "volume", ///< last set value
62 };
63
64 #define OFFSET(x) offsetof(VolumeContext, x)
65 #define A AV_OPT_FLAG_AUDIO_PARAM
66 #define F AV_OPT_FLAG_FILTERING_PARAM
67 #define T AV_OPT_FLAG_RUNTIME_PARAM
68
70 { "volume", "set volume adjustment expression",
72 { "precision", "select mathematical precision",
80 { "replaygain", "Apply replaygain side data when present",
86 { "replaygain_preamp", "Apply replaygain pre-amplification",
88 { "replaygain_noclip", "Apply replaygain clipping prevention",
91 };
92
94
96 {
99
100 if (*pexpr)
101 old = *pexpr;
106 "Error when evaluating the volume expression '%s'\n", expr);
107 *pexpr = old;
109 }
110
112 return 0;
113 }
114
116 {
118
122
124 }
125
127 {
131 }
132
136 {
147 },
152 },
157 }
158 };
160
164
165 return 0;
166 }
167
169 int nb_samples, int volume)
170 {
172 for (
i = 0;
i < nb_samples;
i++)
174 }
175
177 int nb_samples, int volume)
178 {
180 for (
i = 0;
i < nb_samples;
i++)
182 }
183
185 int nb_samples, int volume)
186 {
188 int16_t *smp_dst = (int16_t *)
dst;
189 const int16_t *smp_src = (
const int16_t *)
src;
190 for (
i = 0;
i < nb_samples;
i++)
192 }
193
195 int nb_samples, int volume)
196 {
198 int16_t *smp_dst = (int16_t *)
dst;
199 const int16_t *smp_src = (
const int16_t *)
src;
200 for (
i = 0;
i < nb_samples;
i++)
202 }
203
205 int nb_samples, int volume)
206 {
210 for (
i = 0;
i < nb_samples;
i++)
212 }
213
215 {
217
222 else
224 break;
228 else
230 break;
233 break;
236 break;
239 break;
240 }
241
242 #if ARCH_X86
244 #endif
245 }
246
248 {
250
256 } else {
259 }
260 }
262
266
271 }
274
276 return 0;
277 }
278
280 {
284
288
292 #if FF_API_FRAME_PKT
294 #endif
300
304
309
311 }
312
314 char *res,
int res_len,
int flags)
315 {
318
319 if (!strcmp(cmd, "volume")) {
324 }
325
327 }
328
330 {
339
344 uint32_t peak = 100000;
346
350
353 }
else if (replaygain->
album_gain != INT32_MIN) {
355
358 } else {
360 "values are unknown.\n");
361 }
362 g = gain / 100000.0f;
363 p = peak / 100000.0f;
364
366 "Using gain %f dB from replaygain side data.\n",
g);
367
372
374 }
376 }
377
381 }
385
386 #if FF_API_FRAME_PKT
388 {
392 }
394 #endif
397
399 out_buf = buf;
400 goto end;
401 }
402
403 /* do volume scaling in-place if input buffer is writable */
406 out_buf = buf;
407 } else {
409 if (!out_buf) {
412 }
418 }
419 }
420
422 int p, plane_samples;
423
426 else
428
430 for (p = 0; p < vol->
planes; p++) {
434 }
436 for (p = 0; p < vol->
planes; p++) {
439 vol->
volume, plane_samples);
440 }
441 } else {
442 for (p = 0; p < vol->
planes; p++) {
445 vol->
volume, plane_samples);
446 }
447 }
448 }
449
450 if (buf != out_buf)
452
453 end:
456 }
457
459 {
463 },
464 };
465
467 {
471 },
472 };
473
478 .priv_class = &volume_class,
486 };
static av_cold int init(AVFilterContext *ctx)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
#define FF_ENABLE_DEPRECATION_WARNINGS
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
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
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.
static enum AVSampleFormat sample_fmts[]
static const char *const var_names[]
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
@ VAR_NB_CONSUMED_SAMPLES
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.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int32_t album_gain
Same as track_gain, but for the whole album.
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
A link between two filters.
Link properties exposed to filter code, but not external callers.
static av_cold void uninit(AVFilterContext *ctx)
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.
static av_cold void volume_init(VolumeContext *vol)
static void scale_samples_s32(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
static void scale_samples_s16(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
static int config_output(AVFilterLink *outlink)
AVFILTER_DEFINE_CLASS(volume)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
static int set_volume(AVFilterContext *ctx)
uint32_t track_peak
Peak track amplitude, with 100000 representing full scale (but values may overflow).
#define FILTER_OUTPUTS(array)
static void scale_samples_u8_small(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
static void scale_samples_u8(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
const AVFilter ff_af_volume
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
double var_values[VAR_VARS_NB]
static FilterLink * ff_filter_link(AVFilterLink *link)
@ AV_FRAME_DATA_REPLAYGAIN
ReplayGain information in the form of the AVReplayGain struct.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
static void scale_samples_s16_small(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
attribute_deprecated int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
int32_t track_gain
Track replay gain in microbels (divide by 100000 to get the value in dB).
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
static const char *const precision_str[]
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
void(* scale_samples)(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int nb_samples
number of audio samples (per channel) described by this frame
static const AVFilterPad avfilter_af_volume_outputs[]
#define i(width, name, range_min, range_max)
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx)
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
#define FILTER_QUERY_FUNC2(func)
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Pad name.
static const AVOption volume_options[]
void(* vector_dmul_scalar)(double *dst, const double *src, double mul, int len)
Multiply a vector of double by a scalar double.
@ AV_OPT_TYPE_INT
Underlying C type is int.
void ff_volume_init_x86(VolumeContext *vol)
uint32_t album_peak
Same as track_peak, but for the whole album,.
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
@ AV_SAMPLE_FMT_DBLP
double, planar
#define FF_DISABLE_DEPRECATION_WARNINGS
ReplayGain information (see http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1....
enum AVSampleFormat sample_fmt
Structure to hold side data for an AVFrame.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
#define flags(name, subs,...)
static const AVFilterPad avfilter_af_volume_inputs[]
@ AV_SAMPLE_FMT_DBL
double
@ 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...
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Generated on Fri Aug 22 2025 13:59:07 for FFmpeg by
doxygen
1.8.17