summaryrefslogtreecommitdiff
path: root/libavfilter/af_apad.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2018-12-16 17:00:56 +0100
committerPaul B Mahol <onemda@gmail.com>2018-12-17 19:14:36 +0100
commitd54276f9def8049c5354822d25663d86d524b026 (patch)
tree40c18fbdde8d0a53205fbc026f16da052c2e249b /libavfilter/af_apad.c
parentee1e39a576977fd38c3b94fc56125d31d38833e9 (diff)
downloadffmpeg-d54276f9def8049c5354822d25663d86d524b026.tar.gz
avfilter/af_apad: add pad_dur and whole_dur options
Diffstat (limited to 'libavfilter/af_apad.c')
-rw-r--r--libavfilter/af_apad.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/libavfilter/af_apad.c b/libavfilter/af_apad.c
index f7a4199c64..fbcf6d1349 100644
--- a/libavfilter/af_apad.c
+++ b/libavfilter/af_apad.c
@@ -41,6 +41,8 @@ typedef struct APadContext {
int packet_size;
int64_t pad_len, pad_len_left;
int64_t whole_len, whole_len_left;
+ int64_t pad_dur;
+ int64_t whole_dur;
} APadContext;
#define OFFSET(x) offsetof(APadContext, x)
@@ -50,6 +52,8 @@ static const AVOption apad_options[] = {
{ "packet_size", "set silence packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, { .i64 = 4096 }, 0, INT_MAX, A },
{ "pad_len", "set number of samples of silence to add", OFFSET(pad_len), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, A },
{ "whole_len", "set minimum target number of samples in the audio stream", OFFSET(whole_len), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, A },
+ { "pad_dur", "set duration of silence to add", OFFSET(pad_dur), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, A },
+ { "whole_dur", "set minimum target duration in the audio stream", OFFSET(whole_dur), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, A },
{ NULL }
};
@@ -64,8 +68,6 @@ static av_cold int init(AVFilterContext *ctx)
av_log(ctx, AV_LOG_ERROR, "Both whole and pad length are set, this is not possible\n");
return AVERROR(EINVAL);
}
- s->pad_len_left = s->pad_len;
- s->whole_len_left = s->whole_len;
return 0;
}
@@ -131,6 +133,22 @@ static int request_frame(AVFilterLink *outlink)
return ret;
}
+static int config_output(AVFilterLink *outlink)
+{
+ AVFilterContext *ctx = outlink->src;
+ APadContext *s = ctx->priv;
+
+ if (s->pad_dur)
+ s->pad_len = av_rescale(s->pad_dur, outlink->sample_rate, AV_TIME_BASE);
+ if (s->whole_dur)
+ s->whole_len = av_rescale(s->whole_dur, outlink->sample_rate, AV_TIME_BASE);
+
+ s->pad_len_left = s->pad_len;
+ s->whole_len_left = s->whole_len;
+
+ return 0;
+}
+
static const AVFilterPad apad_inputs[] = {
{
.name = "default",
@@ -144,6 +162,7 @@ static const AVFilterPad apad_outputs[] = {
{
.name = "default",
.request_frame = request_frame,
+ .config_props = config_output,
.type = AVMEDIA_TYPE_AUDIO,
},
{ NULL }