diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-12-18 17:22:36 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-12-18 17:30:31 +0100 |
commit | c311431e291ee90cddb074ef4ba18496755a7406 (patch) | |
tree | d7cdcec0e939ac3d0a03bf1b8643d8a6a069fe3f | |
parent | c2640146e06faa7608a6bfecc36fc66d6a920e6e (diff) | |
download | ffmpeg-c311431e291ee90cddb074ef4ba18496755a7406.tar.gz |
apad: add whole_len and pad_len options.
These options allow padding to a specific length or adding a specific amount if silence.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavfilter/af_apad.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/libavfilter/af_apad.c b/libavfilter/af_apad.c index 823aa969fe..4bf2d8111b 100644 --- a/libavfilter/af_apad.c +++ b/libavfilter/af_apad.c @@ -40,6 +40,8 @@ typedef struct { int64_t next_pts; int packet_size; + int64_t pad_len; + int64_t whole_len; } APadContext; #define OFFSET(x) offsetof(APadContext, x) @@ -47,6 +49,8 @@ typedef struct { 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", "number of samples of silence to add", OFFSET(pad_len), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, A }, + { "whole_len", "target number of samples in the audio stream", OFFSET(whole_len), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, A }, { NULL }, }; @@ -65,6 +69,11 @@ static av_cold int init(AVFilterContext *ctx, const char *args) if ((ret = av_opt_set_from_string(apad, args, NULL, "=", ":")) < 0) return ret; + if (apad->whole_len && apad->pad_len) { + av_log(ctx, AV_LOG_ERROR, "Both whole and pad length are set, this is not possible\n"); + return AVERROR(EINVAL); + } + av_opt_free(apad); return 0; @@ -74,6 +83,10 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame) { AVFilterContext *ctx = inlink->dst; APadContext *apad = ctx->priv; + + if (apad->whole_len) + apad->whole_len -= frame->audio->nb_samples; + apad->next_pts = frame->pts + av_rescale_q(frame->audio->nb_samples, (AVRational){1, inlink->sample_rate}, inlink->time_base); return ff_filter_frame(ctx->outputs[0], frame); } @@ -88,7 +101,21 @@ static int request_frame(AVFilterLink *outlink) if (ret == AVERROR_EOF) { int n_out = apad->packet_size; - AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n_out); + AVFilterBufferRef *outsamplesref; + + if (apad->whole_len > 0) { + apad->pad_len = apad->whole_len; + apad->whole_len = 0; + } + if (apad->pad_len > 0) { + n_out = FFMIN(n_out, apad->pad_len); + apad->pad_len -= n_out; + } + + if(!n_out) + return AVERROR_EOF; + + outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n_out); if (!outsamplesref) return AVERROR(ENOMEM); |