[FFmpeg-devel] [PATCH 3/3] examples/filtering_audio: Make the example a bit more interesting

pkoshevoy at gmail.com pkoshevoy at gmail.com
Thu Apr 18 07:38:50 CEST 2013


From: Pavel Koshevoy <pkoshevoy at gmail.com>

Use atempo and ffplay 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 7a47fbc..f7f7771 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 ffplay 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";
+const char *player       = "ffplay -f s16le -ar 48000 -ac 2 -";
 
 static AVFormatContext *fmt_ctx;
 static AVCodecContext *dec_ctx;
@@ -90,8 +100,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[] = { 60000, -1 };
     const AVFilterLink *outlink;
     AVRational time_base = fmt_ctx->streams[audio_stream_index]->time_base;
 
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list