Go to the documentation of this file.
47 int64_t start, int64_t range,
int curve);
51 int curve0,
int curve1);
54 enum CurveType {
NONE = -1,
TRI,
QSIN,
ESIN,
HSIN,
LOG,
IPAR,
QUA,
CUB,
SQU,
CBR,
PAR,
EXP,
IQSIN,
IHSIN,
DESE,
DESI,
LOSI,
SINC,
ISINC,
NB_CURVES };
56 #define OFFSET(x) offsetof(AudioFadeContext, x)
57 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
58 #define TFLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
95 #define CUBE(a) ((a)*(a)*(a))
102 gain = sin(gain *
M_PI / 2.0);
106 gain = 0.6366197723675814 * asin(gain);
109 gain = 1.0 - cos(
M_PI / 4.0 * (
CUBE(2.0*gain - 1) + 1));
112 gain = (1.0 - cos(gain *
M_PI)) / 2.0;
116 gain = 0.3183098861837907 * acos(1 - 2 * gain);
120 gain =
exp(-11.512925464970227 * (1 - gain));
123 gain =
av_clipd(1 + 0.2 * log10(gain), 0, 1.0);
126 gain = 1 - sqrt(1 - gain);
129 gain = (1 - (1 - gain) * (1 - gain));
144 gain = gain <= 0.5 ?
cbrt(2 * gain) / 2: 1 -
cbrt(2 * (1 - gain)) / 2;
147 gain = gain <= 0.5 ?
CUBE(2 * gain) / 2: 1 -
CUBE(2 * (1 - gain)) / 2;
150 const double a = 1. / (1. - 0.787) - 1;
151 double A = 1. / (1.0 +
exp(0 -((gain-0.5) *
a * 2.0)));
152 double B = 1. / (1.0 +
exp(
a));
153 double C = 1. / (1.0 +
exp(0-
a));
154 gain = (
A -
B) / (
C -
B);
158 gain = gain >= 1.0 ? 1.0 : sin(
M_PI * (1.0 - gain)) / (
M_PI * (1.0 - gain));
161 gain = gain <= 0.0 ? 0.0 : 1.0 - sin(
M_PI * gain) / (
M_PI * gain);
171 #define FADE_PLANAR(name, type) \
172 static void fade_samples_## name ##p(uint8_t **dst, uint8_t * const *src, \
173 int nb_samples, int channels, int dir, \
174 int64_t start, int64_t range, int curve) \
178 for (i = 0; i < nb_samples; i++) { \
179 double gain = fade_gain(curve, start + i * dir, range); \
180 for (c = 0; c < channels; c++) { \
181 type *d = (type *)dst[c]; \
182 const type *s = (type *)src[c]; \
184 d[i] = s[i] * gain; \
189 #define FADE(name, type) \
190 static void fade_samples_## name (uint8_t **dst, uint8_t * const *src, \
191 int nb_samples, int channels, int dir, \
192 int64_t start, int64_t range, int curve) \
194 type *d = (type *)dst[0]; \
195 const type *s = (type *)src[0]; \
198 for (i = 0; i < nb_samples; i++) { \
199 double gain = fade_gain(curve, start + i * dir, range); \
200 for (c = 0; c < channels; c++, k++) \
201 d[k] = s[k] * gain; \
220 switch (outlink->format) {
241 #if CONFIG_AFADE_FILTER
243 static const AVOption afade_options[] = {
248 {
"start_sample",
"set number of first sample to start fading",
OFFSET(start_sample),
AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX,
TFLAGS },
287 if (INT64_MAX -
s->nb_samples <
s->start_sample)
301 if ((!
s->type && (
s->start_sample +
s->nb_samples < cur_sample)) ||
302 (
s->type && (cur_sample + nb_samples < s->start_sample)))
314 if ((!
s->type && (cur_sample + nb_samples < s->start_sample)) ||
315 (
s->type && (
s->start_sample +
s->nb_samples < cur_sample))) {
322 start = cur_sample -
s->start_sample;
324 start =
s->start_sample +
s->nb_samples - cur_sample;
328 s->type ? -1 : 1, start,
329 s->nb_samples,
s->curve);
339 char *res,
int res_len,
int flags)
350 static const AVFilterPad avfilter_af_afade_inputs[] = {
359 static const AVFilterPad avfilter_af_afade_outputs[] = {
374 .
inputs = avfilter_af_afade_inputs,
375 .
outputs = avfilter_af_afade_outputs,
376 .priv_class = &afade_class,
383 #if CONFIG_ACROSSFADE_FILTER
385 static const AVOption acrossfade_options[] = {
386 {
"nb_samples",
"set number of samples for cross fade duration",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64 = 44100}, 1, INT32_MAX/10,
FLAGS },
387 {
"ns",
"set number of samples for cross fade duration",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64 = 44100}, 1, INT32_MAX/10,
FLAGS },
421 #define CROSSFADE_PLANAR(name, type) \
422 static void crossfade_samples_## name ##p(uint8_t **dst, uint8_t * const *cf0, \
423 uint8_t * const *cf1, \
424 int nb_samples, int channels, \
425 int curve0, int curve1) \
429 for (i = 0; i < nb_samples; i++) { \
430 double gain0 = fade_gain(curve0, nb_samples - 1 - i, nb_samples); \
431 double gain1 = fade_gain(curve1, i, nb_samples); \
432 for (c = 0; c < channels; c++) { \
433 type *d = (type *)dst[c]; \
434 const type *s0 = (type *)cf0[c]; \
435 const type *s1 = (type *)cf1[c]; \
437 d[i] = s0[i] * gain0 + s1[i] * gain1; \
442 #define CROSSFADE(name, type) \
443 static void crossfade_samples_## name (uint8_t **dst, uint8_t * const *cf0, \
444 uint8_t * const *cf1, \
445 int nb_samples, int channels, \
446 int curve0, int curve1) \
448 type *d = (type *)dst[0]; \
449 const type *s0 = (type *)cf0[0]; \
450 const type *s1 = (type *)cf1[0]; \
453 for (i = 0; i < nb_samples; i++) { \
454 double gain0 = fade_gain(curve0, nb_samples - 1 - i, nb_samples); \
455 double gain1 = fade_gain(curve1, i, nb_samples); \
456 for (c = 0; c < channels; c++, k++) \
457 d[k] = s0[k] * gain0 + s1[k] * gain1; \
461 CROSSFADE_PLANAR(dbl,
double)
462 CROSSFADE_PLANAR(flt,
float)
463 CROSSFADE_PLANAR(s16, int16_t)
466 CROSSFADE(dbl,
double)
467 CROSSFADE(flt,
float)
468 CROSSFADE(s16, int16_t)
481 if (
s->crossfade_is_over) {
488 }
else if (
ret < 0) {
503 if (nb_samples > 0) {
532 s->crossfade_samples(
out->extended_data, cf[0]->extended_data,
533 cf[1]->extended_data,
534 s->nb_samples,
out->channels,
535 s->curve,
s->curve2);
539 s->crossfade_is_over = 1;
554 s->fade_samples(
out->extended_data, cf[0]->extended_data,
s->nb_samples,
555 outlink->
channels, -1,
s->nb_samples - 1,
s->nb_samples,
s->curve);
574 s->fade_samples(
out->extended_data, cf[1]->extended_data,
s->nb_samples,
575 outlink->
channels, 1, 0,
s->nb_samples,
s->curve2);
579 s->crossfade_is_over = 1;
601 static int acrossfade_config_output(
AVFilterLink *outlink)
606 if (
ctx->inputs[0]->sample_rate !=
ctx->inputs[1]->sample_rate) {
608 "Inputs must have the same sample rate "
609 "%d for in0 vs %d for in1\n",
610 ctx->inputs[0]->sample_rate,
ctx->inputs[1]->sample_rate);
619 switch (outlink->
format) {
635 static const AVFilterPad avfilter_af_acrossfade_inputs[] = {
637 .
name =
"crossfade0",
641 .name =
"crossfade1",
647 static const AVFilterPad avfilter_af_acrossfade_outputs[] = {
651 .config_props = acrossfade_config_output,
657 .
name =
"acrossfade",
662 .priv_class = &acrossfade_class,
663 .
inputs = avfilter_af_acrossfade_inputs,
664 .
outputs = avfilter_af_acrossfade_outputs,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
A list of supported channel layouts.
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
static av_cold int init(AVCodecContext *avctx)
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
enum MovChannelLayoutTag * layouts
#define AVERROR_EOF
End of file.
AVFilter ff_af_acrossfade
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.
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).
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
void(* fade_samples)(uint8_t **dst, uint8_t *const *src, int nb_samples, int channels, int direction, int64_t start, int64_t range, int curve)
static int config_output(AVFilterLink *outlink)
const char * name
Filter name.
A link between two filters.
int channels
Number of channels.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
A filter pad used for either input or output.
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
int channels
number of audio channels, only used for audio.
static const AVFilterPad outputs[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static double fade_gain(int curve, int64_t index, int64_t range)
void(* crossfade_samples)(uint8_t **dst, uint8_t *const *cf0, uint8_t *const *cf1, int nb_samples, int channels, int curve0, int curve1)
Describe the class of an AVClass context structure.
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
filter_frame For filters that do not use the activate() callback
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static int query_formats(AVFilterContext *ctx)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int64_t start_time
int format
agreed upon media format
#define AV_NOPTS_VALUE
Undefined timestamp value.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
@ 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...
#define AVFILTER_DEFINE_CLASS(fname)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
int sample_rate
samples per second
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_TIME_BASE
Internal time base represented as integer.
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Pad name.
int ff_inlink_queued_samples(AVFilterLink *link)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
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.
@ AV_SAMPLE_FMT_DBLP
double, planar
#define FADE_PLANAR(name, type)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
#define flags(name, subs,...)
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
@ AV_SAMPLE_FMT_DBL
double
@ AV_SAMPLE_FMT_S32
signed 32 bits