[FFmpeg-cvslog] libavfilter: Add asettb filter for setting timebase for audio

Nicolas George git at videolan.org
Thu Apr 10 15:09:27 CEST 2014


ffmpeg | branch: master | Nicolas George <george at nsup.org> | Thu Apr  3 15:42:22 2014 +0200| [ad8159e0fe2bfc1c34739f0956ce464f9859b5a7] | committer: Anton Khirnov

libavfilter: Add asettb filter for setting timebase for audio

Ported asettb (including the sr option for audio sample rate) from FFmpeg,
and copied/modified the existing settb documentation for asettb.

Signed-off-by: Katerina Barone-Adesi <katerinab+libav at gmail.com>
Signed-off-by: Anton Khirnov <anton at khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ad8159e0fe2bfc1c34739f0956ce464f9859b5a7
---

 Changelog                |    1 +
 doc/filters.texi         |   41 ++++++++++++++++++++++++++++++++++++++++
 libavfilter/Makefile     |    1 +
 libavfilter/allfilters.c |    1 +
 libavfilter/settb.c      |   47 ++++++++++++++++++++++++++++++++++++++++++++--
 libavfilter/version.h    |    2 +-
 6 files changed, 90 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 5380565..55216e8 100644
--- a/Changelog
+++ b/Changelog
@@ -18,6 +18,7 @@ version <next>:
 - LucasArts SMUSH VIMA audio decoder (ADPCM)
 - LucasArts SMUSH demuxer
 - MP2 encoding via TwoLAME
+- asettb filter
 
 
 version 10:
diff --git a/doc/filters.texi b/doc/filters.texi
index f986623..c34aef2 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -260,6 +260,47 @@ asetpts=expr=N/SR/TB
 asetpts='(RTCTIME - RTCSTART) / (TB * 1000000)"
 @end example
 
+ at section asettb
+
+Set the timebase to use for the output frames timestamps.
+It is mainly useful for testing timebase configuration.
+
+This filter accepts the following parameters:
+
+ at table @option
+
+ at item expr
+The expression which is evaluated into the output timebase.
+
+ at end table
+
+The expression can contain the constants @var{PI}, @var{E}, @var{PHI}, @var{AVTB} (the
+default timebase), @var{intb} (the input timebase), and @var{sr} (the sample rate,
+audio only).
+
+The default value for the input is @var{intb}.
+
+Some examples:
+
+ at example
+# Set the timebase to 1/25:
+settb=1/25
+
+# Set the timebase to 1/10:
+settb=0.1
+
+# Set the timebase to 1001/1000:
+settb=1+0.001
+
+# Set the timebase to 2*intb:
+settb=2*intb
+
+# Set the default timebase value:
+settb=AVTB
+
+# Set the timebase to twice the sample rate:
+asettb=sr*2
+ at end example
 
 @section ashowinfo
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1f5e433..9c5c666 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -28,6 +28,7 @@ OBJS-$(CONFIG_AFORMAT_FILTER)                += af_aformat.o
 OBJS-$(CONFIG_AMIX_FILTER)                   += af_amix.o
 OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
 OBJS-$(CONFIG_ASETPTS_FILTER)                += setpts.o
+OBJS-$(CONFIG_ASETTB_FILTER)                 += settb.o
 OBJS-$(CONFIG_ASHOWINFO_FILTER)              += af_ashowinfo.o
 OBJS-$(CONFIG_ASPLIT_FILTER)                 += split.o
 OBJS-$(CONFIG_ASYNCTS_FILTER)                += af_asyncts.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index ddca153..d7bb47a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -48,6 +48,7 @@ void avfilter_register_all(void)
     REGISTER_FILTER(AMIX,           amix,           af);
     REGISTER_FILTER(ANULL,          anull,          af);
     REGISTER_FILTER(ASETPTS,        asetpts,        af);
+    REGISTER_FILTER(ASETTB,         asettb,         af);
     REGISTER_FILTER(ASHOWINFO,      ashowinfo,      af);
     REGISTER_FILTER(ASPLIT,         asplit,         af);
     REGISTER_FILTER(ASYNCTS,        asyncts,        af);
diff --git a/libavfilter/settb.c b/libavfilter/settb.c
index 87b60a7..962e7b3 100644
--- a/libavfilter/settb.c
+++ b/libavfilter/settb.c
@@ -32,6 +32,7 @@
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "libavutil/rational.h"
+#include "audio.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "video.h"
@@ -42,6 +43,7 @@ static const char *const var_names[] = {
     "PI",
     "AVTB",   /* default timebase 1/AV_TIME_BASE */
     "intb",   /* input timebase */
+    "sr",     /* sample rate */
     NULL
 };
 
@@ -51,6 +53,7 @@ enum var_name {
     VAR_PI,
     VAR_AVTB,
     VAR_INTB,
+    VAR_SR,
     VAR_VARS_NB
 };
 
@@ -74,6 +77,7 @@ static int config_output_props(AVFilterLink *outlink)
     settb->var_values[VAR_PI]   = M_PI;
     settb->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
     settb->var_values[VAR_INTB] = av_q2d(inlink->time_base);
+    settb->var_values[VAR_SR]   = inlink->sample_rate;
 
     outlink->w = inlink->w;
     outlink->h = inlink->h;
@@ -116,12 +120,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 }
 
 #define OFFSET(x) offsetof(SetTBContext, x)
-#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 static const AVOption options[] = {
     { "expr", "Expression determining the output timebase", OFFSET(tb_expr), AV_OPT_TYPE_STRING, { .str = "intb" }, .flags = FLAGS },
     { NULL },
 };
 
+#if CONFIG_SETTB_FILTER
 static const AVClass settb_class = {
     .class_name = "settb",
     .item_name  = av_default_item_name,
@@ -150,7 +155,7 @@ static const AVFilterPad avfilter_vf_settb_outputs[] = {
 
 AVFilter ff_vf_settb = {
     .name      = "settb",
-    .description = NULL_IF_CONFIG_SMALL("Set timebase for the output link."),
+    .description = NULL_IF_CONFIG_SMALL("Set timebase for the video output link."),
 
     .priv_size = sizeof(SetTBContext),
     .priv_class = &settb_class,
@@ -159,3 +164,41 @@ AVFilter ff_vf_settb = {
 
     .outputs   = avfilter_vf_settb_outputs,
 };
+#endif /* CONFIG_SETTB_FILTER */
+
+#if CONFIG_ASETTB_FILTER
+static const AVClass asettb_class = {
+    .class_name = "asettb",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVFilterPad avfilter_af_asettb_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_AUDIO,
+        .get_audio_buffer = ff_null_get_audio_buffer,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad avfilter_af_asettb_outputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_AUDIO,
+        .config_props = config_output_props,
+    },
+    { NULL }
+};
+
+AVFilter ff_af_asettb = {
+    .name        = "asettb",
+    .description = NULL_IF_CONFIG_SMALL("Set timebase for the audio output link."),
+    .priv_size   = sizeof(SetTBContext),
+    .inputs      = avfilter_af_asettb_inputs,
+    .outputs     = avfilter_af_asettb_outputs,
+    .priv_class  = &asettb_class,
+};
+#endif /* CONFIG_ASETTB_FILTER */
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 1fd0eb6..5093e50 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  4
-#define LIBAVFILTER_VERSION_MINOR  3
+#define LIBAVFILTER_VERSION_MINOR  4
 #define LIBAVFILTER_VERSION_MICRO  0
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list