Commit b38c79bf authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'b384e031'

* commit 'b384e031':
  lavfi: add volume filter

Conflicts:
	Changelog
	libavfilter/Makefile
	libavfilter/af_volume.c
	libavfilter/version.h
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 377d2017 b384e031
......@@ -701,96 +701,6 @@ tolerance in @file{silence.mp3}:
ffmpeg -f lavfi -i amovie=silence.mp3,silencedetect=noise=0.0001 -f null -
@end example
@section volume
Adjust the input audio volume.
The filter accepts exactly one parameter @var{vol}, which expresses
how the audio volume will be increased or decreased.
Output values are clipped to the maximum value.
If @var{vol} is expressed as a decimal number, the output audio
volume is given by the relation:
@example
@var{output_volume} = @var{vol} * @var{input_volume}
@end example
If @var{vol} is expressed as a decimal number followed by the string
"dB", the value represents the requested change in decibels of the
input audio power, and the output audio volume is given by the
relation:
@example
@var{output_volume} = 10^(@var{vol}/20) * @var{input_volume}
@end example
Otherwise @var{vol} is considered an expression and its evaluated
value is used for computing the output audio volume according to the
first relation.
Default value for @var{vol} is 1.0.
@subsection Examples
@itemize
@item
Half the input audio volume:
@example
volume=0.5
@end example
The above example is equivalent to:
@example
volume=1/2
@end example
@item
Decrease input audio power by 12 decibels:
@example
volume=-12dB
@end example
@end itemize
@section volumedetect
Detect the volume of the input video.
The filter has no parameters. The input is not modified. Statistics about
the volume will be printed in the log when the input stream end is reached.
In particular it will show the mean volume (root mean square), maximum
volume (on a per-sample basis), and the beginning of an histogram of the
registered volume values (from the maximum value to a cumulated 1/1000 of
the samples).
All volumes are in decibels relative to the maximum PCM value.
Here is an excerpt of the output:
@example
[Parsed_volumedetect_0 @ 0xa23120] mean_volume: -27 dB
[Parsed_volumedetect_0 @ 0xa23120] max_volume: -4 dB
[Parsed_volumedetect_0 @ 0xa23120] histogram_4db: 6
[Parsed_volumedetect_0 @ 0xa23120] histogram_5db: 62
[Parsed_volumedetect_0 @ 0xa23120] histogram_6db: 286
[Parsed_volumedetect_0 @ 0xa23120] histogram_7db: 1042
[Parsed_volumedetect_0 @ 0xa23120] histogram_8db: 2551
[Parsed_volumedetect_0 @ 0xa23120] histogram_9db: 4609
[Parsed_volumedetect_0 @ 0xa23120] histogram_10db: 8409
@end example
It means that:
@itemize
@item
The mean square energy is approximately -27 dB, or 10^-2.7.
@item
The largest sample is at -4 dB, or more precisely between -4 dB and -5 dB.
@item
There are 6 samples at -4 dB, 62 at -5 dB, 286 at -6 dB, etc.
@end itemize
In other words, raising the volume by +4 dB does not cause any clipping,
raising it by +5 dB causes clipping for 6 samples, etc.
@section asyncts
Synchronize audio data with timestamps by squeezing/stretching it and/or
dropping samples/adding silence when needed.
......@@ -919,6 +829,149 @@ out
Convert the audio sample format, sample rate and channel layout. This filter is
not meant to be used directly.
@section volume
Adjust the input audio volume.
The filter accepts exactly one parameter @var{vol}, which expresses
how the audio volume will be increased or decreased.
Output values are clipped to the maximum value.
If @var{vol} is expressed as a decimal number, the output audio
volume is given by the relation:
@example
@var{output_volume} = @var{vol} * @var{input_volume}
@end example
If @var{vol} is expressed as a decimal number followed by the string
"dB", the value represents the requested change in decibels of the
input audio power, and the output audio volume is given by the
relation:
@example
@var{output_volume} = 10^(@var{vol}/20) * @var{input_volume}
@end example
Otherwise @var{vol} is considered an expression and its evaluated
value is used for computing the output audio volume according to the
first relation.
Default value for @var{vol} is 1.0.
@subsection Examples
@itemize
@item
Half the input audio volume:
@example
volume=0.5
@end example
The above example is equivalent to:
@example
volume=1/2
@end example
@item
Decrease input audio power by 12 decibels:
@example
volume=-12dB
@end example
@end itemize
@section volumedetect
Detect the volume of the input video.
The filter has no parameters. The input is not modified. Statistics about
the volume will be printed in the log when the input stream end is reached.
In particular it will show the mean volume (root mean square), maximum
volume (on a per-sample basis), and the beginning of an histogram of the
registered volume values (from the maximum value to a cumulated 1/1000 of
the samples).
All volumes are in decibels relative to the maximum PCM value.
Here is an excerpt of the output:
@example
[Parsed_volumedetect_0 @ 0xa23120] mean_volume: -27 dB
[Parsed_volumedetect_0 @ 0xa23120] max_volume: -4 dB
[Parsed_volumedetect_0 @ 0xa23120] histogram_4db: 6
[Parsed_volumedetect_0 @ 0xa23120] histogram_5db: 62
[Parsed_volumedetect_0 @ 0xa23120] histogram_6db: 286
[Parsed_volumedetect_0 @ 0xa23120] histogram_7db: 1042
[Parsed_volumedetect_0 @ 0xa23120] histogram_8db: 2551
[Parsed_volumedetect_0 @ 0xa23120] histogram_9db: 4609
[Parsed_volumedetect_0 @ 0xa23120] histogram_10db: 8409
@end example
It means that:
@itemize
@item
The mean square energy is approximately -27 dB, or 10^-2.7.
@item
The largest sample is at -4 dB, or more precisely between -4 dB and -5 dB.
@item
There are 6 samples at -4 dB, 62 at -5 dB, 286 at -6 dB, etc.
@end itemize
In other words, raising the volume by +4 dB does not cause any clipping,
raising it by +5 dB causes clipping for 6 samples, etc.
@section volume_justin
Adjust the input audio volume.
The filter accepts the following named parameters:
@table @option
@item volume
Expresses how the audio volume will be increased or decreased.
Output values are clipped to the maximum value.
The output audio volume is given by the relation:
@example
@var{output_volume} = @var{volume} * @var{input_volume}
@end example
Default value for @var{volume} is 1.0.
@item precision
Mathematical precision.
This determines which input sample formats will be allowed, which affects the
precision of the volume scaling.
@table @option
@item fixed
8-bit fixed-point; limits input sample format to U8, S16, and S32.
@item float
32-bit floating-point; limits input sample format to FLT. (default)
@item double
64-bit floating-point; limits input sample format to DBL.
@end table
@end table
@subsection Examples
@itemize
@item
Halve the input audio volume:
@example
volume_justin=volume=0.5
volume_justin=volume=1/2
volume_justin=volume=-6.0206dB
@end example
@item
Increase input audio power by 6 decibels using fixed-point precision:
@example
volume_justin=volume=6dB:precision=fixed
@end example
@end itemize
@c man end AUDIO FILTERS
@chapter Audio Sources
......
......@@ -72,6 +72,7 @@ OBJS-$(CONFIG_PAN_FILTER) += af_pan.o
OBJS-$(CONFIG_RESAMPLE_FILTER) += af_resample.o
OBJS-$(CONFIG_SILENCEDETECT_FILTER) += af_silencedetect.o
OBJS-$(CONFIG_VOLUME_FILTER) += af_volume.o
OBJS-$(CONFIG_VOLUME_JUSTIN_FILTER) += af_volume_justin.o
OBJS-$(CONFIG_VOLUMEDETECT_FILTER) += af_volumedetect.o
OBJS-$(CONFIG_AEVALSRC_FILTER) += asrc_aevalsrc.o
......
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* audio volume filter
*/
#ifndef AVFILTER_AF_VOLUME_H
#define AVFILTER_AF_VOLUME_H
#include "libavutil/common.h"
#include "libavutil/float_dsp.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
enum PrecisionType {
PRECISION_FIXED = 0,
PRECISION_FLOAT,
PRECISION_DOUBLE,
};
typedef struct VolumeContext {
const AVClass *class;
AVFloatDSPContext fdsp;
enum PrecisionType precision;
double volume;
int volume_i;
int channels;
int planes;
enum AVSampleFormat sample_fmt;
void (*scale_samples)(uint8_t *dst, const uint8_t *src, int nb_samples,
int volume);
int samples_align;
} VolumeContext;
#endif /* AVFILTER_AF_VOLUME_H */
This diff is collapsed.
......@@ -61,10 +61,11 @@ void avfilter_register_all(void)
REGISTER_FILTER (EBUR128, ebur128, af);
REGISTER_FILTER (JOIN, join, af);
REGISTER_FILTER (PAN, pan, af);
REGISTER_FILTER (RESAMPLE, resample, af);
REGISTER_FILTER (SILENCEDETECT, silencedetect, af);
REGISTER_FILTER (VOLUME, volume, af);
REGISTER_FILTER (VOLUME_JUSTIN, volume_justin, af);
REGISTER_FILTER (VOLUMEDETECT,volumedetect,af);
REGISTER_FILTER (RESAMPLE, resample, af);
REGISTER_FILTER (AEVALSRC, aevalsrc, asrc);
REGISTER_FILTER (ANULLSRC, anullsrc, asrc);
......
......@@ -29,7 +29,7 @@
#include "libavutil/avutil.h"
#define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 24
#define LIBAVFILTER_VERSION_MINOR 25
#define LIBAVFILTER_VERSION_MICRO 100
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment