41 int nb_samples,
int channels,
int direction,
42 int64_t
start,
int range,
int curve);
47 #define OFFSET(x) offsetof(AudioFadeContext, x)
48 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
55 {
"start_sample",
"set number of first sample to start fading",
OFFSET(start_sample),
AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX,
FLAGS },
57 {
"nb_samples",
"set number of samples for fade duration",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64 = 44100}, 1, INT32_MAX,
FLAGS },
127 gain =
FFMAX(0.0,
FFMIN(1.0, 1.0 * index / range));
131 gain = sin(gain *
M_PI / 2.0);
134 gain = 1.0 - cos(
M_PI / 4.0 * (pow(2.0*gain - 1, 3) + 1));
137 gain = (1.0 - cos(gain *
M_PI)) / 2.0;
140 gain = pow(0.1, (1 - gain) * 5.0);
143 gain = (1 - (1 - gain) * (1 - gain));
149 gain = gain * gain * gain;
162 #define FADE_PLANAR(name, type) \
163 static void fade_samples_## name ##p(uint8_t **dst, uint8_t * const *src, \
164 int nb_samples, int channels, int dir, \
165 int64_t start, int range, int curve) \
169 for (i = 0; i < nb_samples; i++) { \
170 double gain = fade_gain(curve, start + i * dir, range); \
171 for (c = 0; c < channels; c++) { \
172 type *d = (type *)dst[c]; \
173 const type *s = (type *)src[c]; \
175 d[i] = s[i] * gain; \
180 #define FADE(name, type) \
181 static void fade_samples_## name (uint8_t **dst, uint8_t * const *src, \
182 int nb_samples, int channels, int dir, \
183 int64_t start, int range, int curve) \
185 type *d = (type *)dst[0]; \
186 const type *s = (type *)src[0]; \
189 for (i = 0; i < nb_samples; i++) { \
190 double gain = fade_gain(curve, start + i * dir, range); \
191 for (c = 0; c < channels; c++, k++) \
192 d[k] = s[k] * gain; \
211 switch (inlink->format) {
238 if ((!
s->type && (
s->start_sample +
s->nb_samples < cur_sample)) ||
239 (
s->type && (cur_sample +
s->nb_samples <
s->start_sample)))
251 if ((!
s->type && (cur_sample + nb_samples < s->start_sample)) ||
252 (
s->type && (
s->start_sample +
s->nb_samples < cur_sample))) {
259 start = cur_sample -
s->start_sample;
261 start =
s->start_sample +
s->nb_samples - cur_sample;
263 s->fade_samples(out_buf->extended_data,
buf->extended_data,
265 s->type ? -1 : 1, start,
266 s->nb_samples,
s->curve);
299 .
inputs = avfilter_af_afade_inputs,
300 .
outputs = avfilter_af_afade_outputs,
301 .priv_class = &afade_class,
static double fade_gain(int curve, int64_t index, int range)
This structure describes decoded (raw) audio or video data.
static const AVFilterPad avfilter_af_afade_inputs[]
static const AVFilterPad outputs[]
Main libavfilter public API header.
static enum AVSampleFormat formats[]
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int64_t start_time
static int query_formats(AVFilterContext *ctx)
#define FADE_PLANAR(name, type)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
void(* fade_samples)(uint8_t **dst, uint8_t *const *src, int nb_samples, int channels, int direction, int64_t start, int range, int curve)
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
static av_always_inline double cbrt(double x)
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
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
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
#define AV_TIME_BASE
Internal time base represented as integer.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
AVFILTER_DEFINE_CLASS(afade)
static const AVOption afade_options[]
A list of supported channel layouts.
static const AVFilterPad avfilter_af_afade_outputs[]
AVSampleFormat
Audio sample formats.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Describe the class of an AVClass context structure.
int av_frame_get_channels(const AVFrame *frame)
static const AVFilterPad inputs[]
rational number numerator/denominator
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
static int config_input(AVFilterLink *inlink)
static av_cold int init(AVFilterContext *ctx)
AVFilterContext * dst
dest filter
static enum AVSampleFormat sample_fmts[]
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
int nb_samples
number of audio samples (per channel) described by this frame
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.