mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-21 10:55:51 +02:00
lavfi: add aformat filter
Signed-off-by: Stefano Sabatini <stefano.sabatini-lala@poste.it>
This commit is contained in:
parent
3f07d40ea2
commit
0a2295815d
@ -99,6 +99,27 @@ build.
|
||||
|
||||
Below is a description of the currently available audio filters.
|
||||
|
||||
@section aformat
|
||||
|
||||
Convert the input audio to one of the specified formats. The framework will
|
||||
negotiate the most appropriate format to minimize conversions.
|
||||
|
||||
The filter accepts three lists of formats, separated by ":", in the form:
|
||||
"@var{sample_formats}:@var{channel_layouts}:@var{packing_formats}".
|
||||
|
||||
Elements in each list are separated by "," which has to be escaped in the
|
||||
filtergraph specification.
|
||||
|
||||
The special parameter "all", in place of a list of elements, signifies all
|
||||
supported formats.
|
||||
|
||||
Some examples follow:
|
||||
@example
|
||||
aformat=u8\\,s16:mono:packed
|
||||
|
||||
aformat=s16:mono\\,stereo:all
|
||||
@end example
|
||||
|
||||
@section anull
|
||||
|
||||
Pass the audio source unchanged to the output.
|
||||
|
@ -18,6 +18,7 @@ OBJS = allfilters.o \
|
||||
|
||||
OBJS-$(CONFIG_AVCODEC) += avcodec.o
|
||||
|
||||
OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o
|
||||
OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o
|
||||
|
||||
OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o
|
||||
|
114
libavfilter/af_aformat.c
Normal file
114
libavfilter/af_aformat.c
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Mina Nagy Zaki
|
||||
*
|
||||
* 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
|
||||
* format audio filter
|
||||
*/
|
||||
|
||||
#include "libavutil/audioconvert.h"
|
||||
#include "avfilter.h"
|
||||
#include "internal.h"
|
||||
|
||||
typedef struct {
|
||||
AVFilterFormats *formats, *chlayouts, *packing;
|
||||
} AFormatContext;
|
||||
|
||||
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
|
||||
{
|
||||
AFormatContext * const aformat = ctx->priv;
|
||||
char *arg, *fmt_str;
|
||||
int64_t fmt;
|
||||
int ret;
|
||||
|
||||
arg = strsep(&args, ":");
|
||||
if (!arg) goto arg_fail;
|
||||
if (!strcmp(arg, "all")) {
|
||||
aformat->formats = avfilter_all_formats(AVMEDIA_TYPE_AUDIO);
|
||||
} else {
|
||||
while (fmt_str = strsep(&arg, ",")) {
|
||||
if ((ret = ff_parse_sample_format((int*)&fmt, fmt_str, ctx)) < 0)
|
||||
return ret;
|
||||
avfilter_add_format(&aformat->formats, fmt);
|
||||
}
|
||||
}
|
||||
|
||||
arg = strsep(&args, ":");
|
||||
if (!arg) goto arg_fail;
|
||||
if (!strcmp(arg, "all")) {
|
||||
aformat->chlayouts = avfilter_all_channel_layouts();
|
||||
} else {
|
||||
while (fmt_str = strsep(&arg, ",")) {
|
||||
if ((ret = ff_parse_channel_layout(&fmt, fmt_str, ctx)) < 0)
|
||||
return ret;
|
||||
avfilter_add_format(&aformat->chlayouts, fmt);
|
||||
}
|
||||
}
|
||||
|
||||
arg = strsep(&args, ":");
|
||||
if (!arg) goto arg_fail;
|
||||
if (!strcmp(arg, "all")) {
|
||||
aformat->packing = avfilter_all_packing_formats();
|
||||
} else {
|
||||
while (fmt_str = strsep(&arg, ",")) {
|
||||
if ((ret = ff_parse_packing_format((int*)&fmt, fmt_str, ctx)) < 0)
|
||||
return ret;
|
||||
avfilter_add_format(&aformat->packing, fmt);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
arg_fail:
|
||||
av_log(ctx, AV_LOG_ERROR, "Invalid arguments, they must be of the form "
|
||||
"sample_fmts:channel_layouts:packing_fmts\n");
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
static int query_formats(AVFilterContext *ctx)
|
||||
{
|
||||
AFormatContext * const aformat = ctx->priv;
|
||||
|
||||
avfilter_set_common_sample_formats (ctx, aformat->formats);
|
||||
avfilter_set_common_channel_layouts(ctx, aformat->chlayouts);
|
||||
avfilter_set_common_packing_formats(ctx, aformat->packing);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
|
||||
{
|
||||
avfilter_filter_samples(inlink->dst->outputs[0], insamplesref);
|
||||
}
|
||||
|
||||
AVFilter avfilter_af_aformat = {
|
||||
.name = "aformat",
|
||||
.description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
|
||||
.init = init,
|
||||
.query_formats = query_formats,
|
||||
.priv_size = sizeof(AFormatContext),
|
||||
|
||||
.inputs = (AVFilterPad[]) {{ .name = "default",
|
||||
.type = AVMEDIA_TYPE_AUDIO,
|
||||
.filter_samples = filter_samples},
|
||||
{ .name = NULL}},
|
||||
.outputs = (AVFilterPad[]) {{ .name = "default",
|
||||
.type = AVMEDIA_TYPE_AUDIO},
|
||||
{ .name = NULL}},
|
||||
};
|
@ -34,6 +34,7 @@ void avfilter_register_all(void)
|
||||
return;
|
||||
initialized = 1;
|
||||
|
||||
REGISTER_FILTER (AFORMAT, aformat, af);
|
||||
REGISTER_FILTER (ANULL, anull, af);
|
||||
|
||||
REGISTER_FILTER (ANULLSRC, anullsrc, asrc);
|
||||
|
@ -29,8 +29,8 @@
|
||||
#include "libavutil/rational.h"
|
||||
|
||||
#define LIBAVFILTER_VERSION_MAJOR 2
|
||||
#define LIBAVFILTER_VERSION_MINOR 29
|
||||
#define LIBAVFILTER_VERSION_MICRO 2
|
||||
#define LIBAVFILTER_VERSION_MINOR 30
|
||||
#define LIBAVFILTER_VERSION_MICRO 0
|
||||
|
||||
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
||||
LIBAVFILTER_VERSION_MINOR, \
|
||||
|
Loading…
Reference in New Issue
Block a user