[FFmpeg-devel] [PATCH] lavfi/apad: fix logic when whole_len or pad_len options are specified
Stefano Sabatini
stefasab at gmail.com
Mon Aug 18 14:53:45 CEST 2014
---
libavfilter/af_apad.c | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/libavfilter/af_apad.c b/libavfilter/af_apad.c
index 15ba8c4..c58cacf 100644
--- a/libavfilter/af_apad.c
+++ b/libavfilter/af_apad.c
@@ -39,8 +39,8 @@ typedef struct {
int64_t next_pts;
int packet_size;
- int64_t pad_len;
- int64_t whole_len;
+ int64_t pad_len, pad_len_left;
+ int64_t whole_len, whole_len_left;
} APadContext;
#define OFFSET(x) offsetof(APadContext, x)
@@ -48,8 +48,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 },
+ { "pad_len", "set number of samples of silence to add", OFFSET(pad_len), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, A },
+ { "whole_len", "set target number of samples in the audio stream", OFFSET(whole_len), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, A },
{ NULL }
};
@@ -64,6 +64,8 @@ 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);
}
+ apad->pad_len_left = apad->pad_len;
+ apad->whole_len_left = apad->whole_len;
return 0;
}
@@ -73,8 +75,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
AVFilterContext *ctx = inlink->dst;
APadContext *apad = ctx->priv;
- if (apad->whole_len)
- apad->whole_len -= frame->nb_samples;
+ if (apad->whole_len) {
+ apad->whole_len_left = FFMAX(apad->whole_len_left - frame->nb_samples, 0);
+ av_log(ctx, AV_LOG_DEBUG, "whole_len_left:%"PRId64"\n", apad->whole_len_left);
+ }
apad->next_pts = frame->pts + av_rescale_q(frame->nb_samples, (AVRational){1, inlink->sample_rate}, inlink->time_base);
return ff_filter_frame(ctx->outputs[0], frame);
@@ -92,13 +96,14 @@ static int request_frame(AVFilterLink *outlink)
int n_out = apad->packet_size;
AVFrame *outsamplesref;
- if (apad->whole_len > 0) {
- apad->pad_len = apad->whole_len;
- apad->whole_len = 0;
+ if (apad->whole_len > 0 && !apad->pad_len) {
+ apad->pad_len = apad->pad_len_left = apad->whole_len_left;
}
- if (apad->pad_len > 0) {
- n_out = FFMIN(n_out, apad->pad_len);
- apad->pad_len -= n_out;
+ if (apad->pad_len > 0 || apad->whole_len > 0) {
+ n_out = FFMIN(n_out, apad->pad_len_left);
+ apad->pad_len_left -= n_out;
+ av_log(ctx, AV_LOG_DEBUG,
+ "n_out:%d pad_len_left:%"PRId64"\n", n_out, apad->pad_len_left);
}
if(!n_out)
--
1.8.3.2
More information about the ffmpeg-devel
mailing list