[FFmpeg-devel] [PATCH] examples/filtering_audio: Make the example a bit more interesting
Stefano Sabatini
stefasab at gmail.com
Sat May 4 15:56:36 CEST 2013
On date Sunday 2013-04-21 09:33:14 -0600, pkoshevoy at gmail.com encoded:
> From: Pavel Koshevoy <pkoshevoy at gmail.com>
>
> Use atempo and asetrate to produce a pitch shifting effect.
>
> Signed-off-by: Pavel Koshevoy <pkoshevoy at gmail.com>
> ---
> doc/examples/filtering_audio.c | 18 ++++++++++++++----
> 1 file changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
> index b6b05a2..cf929a7 100644
> --- a/doc/examples/filtering_audio.c
> +++ b/doc/examples/filtering_audio.c
> @@ -38,8 +38,18 @@
> #include <libavfilter/buffersrc.h>
> #include <libavutil/opt.h>
>
> -const char *filter_descr = "aresample=8000,aformat=sample_fmts=s16:channel_layouts=mono";
> -const char *player = "ffplay -f s16le -ar 8000 -ac 1 -";
> +/*
> + * Example of pitch-shifting effect:
> + *
> + * 1. use atempo filter at 60KHz sample rate and increase playback tempo
> + * by a factor of 1.25, which is equivalent to 48000 samples per second
> + * at 48KHz sample rate.
> + *
> + * 2. use asetrate to ingest raw audio at 48KHz thus increasing playback
> + * duration by a factor of 1.25 and resulting in playback at a lower pitch.
> +*/
> +const char *filter_descr = "aresample=60000,atempo=1.25,asetrate=48000";
Or we could make it parametrizable, and make the example accept a
string containing the graph description (possibly overkill).
Also we could make asetrate parametric, this could become for example:
atempo=1.25,asetrate=in_rate/1.25
> +const char *player = "ffplay -f s16le -ar 48000 -ac 2 -";
>
> static AVFormatContext *fmt_ctx;
> static AVCodecContext *dec_ctx;
> @@ -91,8 +101,8 @@ static int init_filters(const char *filters_descr)
> AVFilterInOut *outputs = avfilter_inout_alloc();
> AVFilterInOut *inputs = avfilter_inout_alloc();
> const enum AVSampleFormat out_sample_fmts[] = { AV_SAMPLE_FMT_S16, -1 };
> - const int64_t out_channel_layouts[] = { AV_CH_LAYOUT_MONO, -1 };
> - const int out_sample_rates[] = { 8000, -1 };
> + const int64_t out_channel_layouts[] = { AV_CH_LAYOUT_STEREO, -1 };
> + const int out_sample_rates[] = { 48000, -1 };
> const AVFilterLink *outlink;
> AVRational time_base = fmt_ctx->streams[audio_stream_index]->time_base;
[...]
--
FFmpeg = Free and Fiendish Mournful Patchable Esoteric Gadget
More information about the ffmpeg-devel
mailing list