aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-11-01 13:22:09 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-11-01 13:22:09 +0100
commit20071ff1a4ba0730455995e354d5168c46d1cd71 (patch)
treef488dbf75628419e0311142810601e704d941fd1
parent3b7db9c4f55ddc51f5f29d169d379fe2c6402b11 (diff)
parentca8c62d187fdca13979379fb2ab172ed662aa2f8 (diff)
downloadffmpeg-20071ff1a4ba0730455995e354d5168c46d1cd71.tar.gz
Merge commit 'ca8c62d187fdca13979379fb2ab172ed662aa2f8' into release/2.4
* commit 'ca8c62d187fdca13979379fb2ab172ed662aa2f8': resample: Avoid off-by-1 errors in PTS calcs. Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavfilter/af_resample.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/libavfilter/af_resample.c b/libavfilter/af_resample.c
index 03467a747b..f4b396a452 100644
--- a/libavfilter/af_resample.c
+++ b/libavfilter/af_resample.c
@@ -41,6 +41,7 @@ typedef struct ResampleContext {
AVDictionary *options;
int64_t next_pts;
+ int64_t next_in_pts;
/* set by filter_frame() to signal an output frame to request_frame() */
int got_output;
@@ -153,6 +154,7 @@ static int config_output(AVFilterLink *outlink)
outlink->time_base = (AVRational){ 1, outlink->sample_rate };
s->next_pts = AV_NOPTS_VALUE;
+ s->next_in_pts = AV_NOPTS_VALUE;
av_get_channel_layout_string(buf1, sizeof(buf1),
-1, inlink ->channel_layout);
@@ -254,7 +256,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
out->sample_rate = outlink->sample_rate;
- if (in->pts != AV_NOPTS_VALUE) {
+ /* Only convert in->pts if there is a discontinuous jump.
+ This ensures that out->pts tracks the number of samples actually
+ output by the resampler in the absence of such a jump.
+ Otherwise, the rounding in av_rescale_q() and av_rescale()
+ causes off-by-1 errors. */
+ if (in->pts != AV_NOPTS_VALUE && in->pts != s->next_in_pts) {
out->pts = av_rescale_q(in->pts, inlink->time_base,
outlink->time_base) -
av_rescale(delay, outlink->sample_rate,
@@ -263,6 +270,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
out->pts = s->next_pts;
s->next_pts = out->pts + out->nb_samples;
+ s->next_in_pts = in->pts + in->nb_samples;
ret = ff_filter_frame(outlink, out);
s->got_output = 1;