51#define DURATION_LONGEST 0
52#define DURATION_SHORTEST 1
53#define DURATION_FIRST 2
80 while (frame_list->
list) {
93 if (!frame_list->
list)
100 if (!frame_list->
list)
110 int samples = nb_samples;
111 while (samples > 0) {
117 if (!frame_list->
list)
124 info->
pts += samples;
141 if (!frame_list->
list) {
142 frame_list->
list = info;
143 frame_list->
end = info;
147 frame_list->
end = info;
181#define OFFSET(x) offsetof(MixContext, x)
182#define A AV_OPT_FLAG_AUDIO_PARAM
183#define F AV_OPT_FLAG_FILTERING_PARAM
184#define T AV_OPT_FLAG_RUNTIME_PARAM
186 {
"inputs",
"Number of inputs.",
188 {
"duration",
"How to determine the end-of-stream.",
193 {
"dropout_transition",
"Transition time, in seconds, for volume "
194 "renormalization when an input stream ends.",
196 {
"weights",
"Set weight for each input.",
198 {
"normalize",
"Scale inputs",
214 float weight_sum = 0.f;
217 for (
i = 0;
i <
s->nb_inputs;
i++)
219 weight_sum +=
FFABS(
s->weights[
i]);
221 for (
i = 0;
i <
s->nb_inputs;
i++) {
223 if (
s->scale_norm[
i] > weight_sum /
FFABS(
s->weights[
i])) {
224 s->scale_norm[
i] -= ((
s->weight_sum /
FFABS(
s->weights[
i])) /
s->nb_inputs) *
225 nb_samples / (
s->dropout_transition *
s->sample_rate);
226 s->scale_norm[
i] =
FFMAX(
s->scale_norm[
i], weight_sum /
FFABS(
s->weights[
i]));
231 for (
i = 0;
i <
s->nb_inputs;
i++) {
234 s->input_scale[
i] =
FFABS(
s->weights[
i]);
236 s->input_scale[
i] = 1.0f /
s->scale_norm[
i] *
FFSIGN(
s->weights[
i]);
238 s->input_scale[
i] = 0.0f;
264 for (
i = 0;
i <
s->nb_inputs;
i++) {
273 memset(
s->input_state,
INPUT_ON,
s->nb_inputs);
274 s->active_inputs =
s->nb_inputs;
276 s->input_scale =
av_calloc(
s->nb_inputs,
sizeof(*
s->input_scale));
277 s->scale_norm =
av_calloc(
s->nb_inputs,
sizeof(*
s->scale_norm));
278 if (!
s->input_scale || !
s->scale_norm)
280 for (
i = 0;
i <
s->nb_inputs;
i++)
281 s->scale_norm[
i] =
s->weight_sum /
FFABS(
s->weights[
i]);
287 "inputs:%d fmt:%s srate:%d cl:%s\n",
s->nb_inputs,
301 int nb_samples, ns,
i;
306 for (
i = 1;
i <
s->nb_inputs;
i++) {
309 if (ns < nb_samples) {
322 nb_samples = INT_MAX;
323 for (
i = 1;
i <
s->nb_inputs;
i++) {
326 nb_samples =
FFMIN(nb_samples, ns);
329 if (nb_samples == INT_MAX) {
352 for (
i = 0;
i <
s->nb_inputs;
i++) {
354 int planes, plane_size, p;
359 planes =
s->planar ?
s->nb_channels : 1;
360 plane_size = nb_samples * (
s->planar ? 1 :
s->nb_channels);
361 plane_size =
FFALIGN(plane_size, 16);
365 for (p = 0; p <
planes; p++) {
368 s->input_scale[
i], plane_size);
371 for (p = 0; p <
planes; p++) {
374 s->input_scale[
i], plane_size);
381 out_buf->
pts =
s->next_pts;
386 s->next_pts += nb_samples;
403 for (
i = 1;
i <
s->nb_inputs;
i++) {
424 int active_inputs = 0;
425 for (
i = 0;
i <
s->nb_inputs;
i++)
426 active_inputs += !!(
s->input_state[
i] &
INPUT_ON);
427 s->active_inputs = active_inputs;
429 if (!active_inputs ||
445 for (
i = 0;
i <
s->nb_inputs;
i++) {
474 for (
i = 0;
i <
s->nb_inputs;
i++) {
483 if (
s->nb_inputs == 1) {
503 if (
s->frame_list->nb_frames == 0) {
520 float last_weight = 1.f;
526 for (
i = 0;
i <
s->nb_inputs;
i++) {
528 s->weights[
i] = last_weight;
529 s->weight_sum +=
FFABS(last_weight);
538 for (;
i <
s->nb_inputs;
i++) {
539 s->weights[
i] = last_weight;
540 s->weight_sum +=
FFABS(last_weight);
549 for (
i = 0;
i <
s->nb_inputs;
i++) {
565 s->weights =
av_calloc(
s->nb_inputs,
sizeof(*
s->weights));
580 for (
i = 0;
i <
s->nb_inputs;
i++)
594 char *res,
int res_len,
int flags)
604 for (
int i = 0;
i <
s->nb_inputs;
i++)
605 s->scale_norm[
i] =
s->weight_sum /
FFABS(
s->weights[
i]);
622 .p.priv_class = &amix_class,
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int output_frame(AVFilterLink *outlink)
Read samples from the input FIFOs, mix, and write to the output link.
static int frame_list_add_frame(FrameList *frame_list, int nb_samples, int64_t pts)
static void calculate_scales(MixContext *s, int nb_samples)
Update the scaling factors to apply to each input during mixing.
static int64_t frame_list_next_pts(FrameList *frame_list)
static void parse_weights(AVFilterContext *ctx)
#define DURATION_SHORTEST
static int calc_active_inputs(MixContext *s)
Calculates the number of active inputs and determines EOF based on the duration option.
static void frame_list_remove_samples(FrameList *frame_list, int nb_samples)
#define INPUT_EOF
input has reached EOF (may still be active)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad avfilter_af_amix_outputs[]
static int frame_list_next_frame_size(FrameList *frame_list)
static void frame_list_clear(FrameList *frame_list)
static int config_output(AVFilterLink *outlink)
static int request_samples(AVFilterContext *ctx, int min_samples)
Requests a frame, if needed, from each input link other than the first.
static const AVOption amix_options[]
#define INPUT_ON
input is active
const FFFilter ff_af_amix
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
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.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Main libavfilter public API header.
char * av_asprintf(const char *fmt,...)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
common internal and external API header
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int(* init)(AVBSFContext *ctx)
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
simple arithmetic expression evaluator
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ 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...
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int av_audio_fifo_write(AVAudioFifo *af, void *const *data, int nb_samples)
Write data to an AVAudioFifo.
int av_audio_fifo_read(AVAudioFifo *af, void *const *data, int nb_samples)
Read data from an AVAudioFifo.
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
#define AVERROR_EOF
End of file.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_VERBOSE
Detailed information.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
@ AV_SAMPLE_FMT_FLTP
float, planar
@ AV_SAMPLE_FMT_DBLP
double, planar
@ AV_SAMPLE_FMT_DBL
double
#define AV_NOPTS_VALUE
Undefined timestamp value.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_OUTPUTS(array)
#define FILTER_SAMPLEFMTS(...)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
#define AVFILTER_DEFINE_CLASS(fname)
Macro definitions for various function/variable attributes.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const struct @257111027162314367033347246032313251342043035002 planes[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
Context for an Audio FIFO Buffer.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A link between two filters.
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int sample_rate
samples per second
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
int format
agreed upon media format
A filter pad used for either input or output.
enum AVMediaType type
AVFilterPad type.
const char * name
Pad name.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int64_t duration
Duration of the frame, in the same units as pts.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
uint8_t ** extended_data
pointers to the data planes/channels.
Rational number (pair of numerator and denominator).
Linked list used to store timestamps and frame sizes of all frames in the FIFO for the first input.
int nb_inputs
number of inputs
int64_t next_pts
calculated pts for next output frame
int active_inputs
number of input currently active
int nb_channels
number of channels
uint8_t * input_state
current state of each input
AVAudioFifo ** fifos
audio fifo for each input
float * scale_norm
normalization factor for every input
int duration_mode
mode for determining duration
char * weights_str
string for custom weights for every input
float * weights
custom weights for every input
float * input_scale
mixing scale factor for each input
FrameList * frame_list
list of frame info for the first input
int sample_rate
sample rate
float weight_sum
sum of custom weights for every input
float dropout_transition
transition time when an input drops out
static AVFormatContext * ctx